What Each Field Means

FieldWhat it is for
nameThe package name. Lowercase, no spaces; must be unique if you publish to npm.
versionThe version, using semantic versioning: MAJOR.MINOR.PATCH.
description, keywordsHelp people find the package on npm.
homepage, bugs, repositoryLinks to the project website, issue tracker and source code.
licenseThe license, for example MIT or Apache-2.0.
type"module" lets you use import/export in .js files; leave it out for CommonJS (require).
main, types, exportsWhich files other projects load when they import your package.
filesWhich files are included when you publish to npm.
enginesWhich Node.js versions the project supports.
scriptsCommands you run with npm run, like npm run build or npm test.
dependenciesPackages needed to run the project.
devDependenciesPackages only needed while developing, such as linters and test tools.

Tips

  • Run npm init -y to create a basic package.json, then copy the fields you need from this template.
  • Add packages with npm install name or npm install -D name instead of editing versions by hand.
  • package.json must be valid JSON: no comments and no trailing commas. Check it with our JSON Validator.

Frequently Asked Questions

What is package.json?

package.json is the main settings file of a Node.js or JavaScript project. It lists the project name and version, scripts, dependencies and other metadata used by npm, yarn and pnpm.

Can package.json have comments?

No. package.json must be valid JSON, so comments are not allowed. That is why the explanations are shown next to the template instead of inside it.

What is the difference between dependencies and devDependencies?

dependencies are needed to run your project. devDependencies are only needed while developing and building, such as test tools, linters and bundlers.

Related Tools