What Each Field Means
| Field | What it is for |
|---|---|
name | The package name. Lowercase, no spaces; must be unique if you publish to npm. |
version | The version, using semantic versioning: MAJOR.MINOR.PATCH. |
description, keywords | Help people find the package on npm. |
homepage, bugs, repository | Links to the project website, issue tracker and source code. |
license | The 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, exports | Which files other projects load when they import your package. |
files | Which files are included when you publish to npm. |
engines | Which Node.js versions the project supports. |
scripts | Commands you run with npm run, like npm run build or npm test. |
dependencies | Packages needed to run the project. |
devDependencies | Packages only needed while developing, such as linters and test tools. |
Tips
- Run
npm init -yto create a basic package.json, then copy the fields you need from this template. - Add packages with
npm install nameornpm install -D nameinstead 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.