Skip to content

package.json Cheat Sheet

General Information Fields

FieldDescriptionExample
nameThe name of your project or package. Must be lowercase and URL-friendly."name": "my-app"
versionVersion number for your package. Follows semantic versioning (semver)."version": "1.0.0"
descriptionShort description of the project."description": "A web app for managing tasks"
authorName and email of the author."author": "John Doe <john@example.com>"
licenseLicense for the project (e.g., MIT, ISC)."license": "MIT"
privateSet to true to prevent package from being published to npm registry."private": true
repositoryThe location of the project’s source code. Can be a Git repository."repository": { "type": "git", "url": "git+https://github.com/user/repo.git" }
homepageURL to the project's homepage."homepage": "https://example.com"
keywordsArray of keywords that describe the package for search purposes."keywords": ["tasks", "management", "web"]

Scripts

FieldDescriptionExample
scriptsDefines custom scripts that can be run via npm run."scripts": { "start": "node index.js", "test": "jest" }
Common ScriptsPredefined scripts often included in package.json.start, test, build, lint, prepublish, postinstall

Dependencies

FieldDescriptionExample
dependenciesLists runtime dependencies needed for the project to work."dependencies": { "express": "^4.17.1" }
devDependenciesLists development dependencies used for testing, building, etc."devDependencies": { "jest": "^27.0.0" }
peerDependenciesSpecifies packages that your package needs to work correctly but won't automatically install."peerDependencies": { "react": "^17.0.0" }
optionalDependenciesDependencies that are optional. These won't break the package if missing."optionalDependencies": { "fsevents": "^1.2.7" }
bundledDependenciesA list of packages that will be bundled when publishing your package."bundledDependencies": [ "module1", "module2" ]
enginesSpecifies which versions of Node.js and npm your package is compatible with."engines": { "node": ">=12", "npm": ">=6" }
resolutionsOverrides versions of nested dependencies for Yarn (useful for fixing vulnerabilities)."resolutions": { "lodash": "^4.17.20" }

Versioning and Semver

SymbolMeaningExample
^Allows updates to the most recent minor version."express": "^4.17.1" (compatible with 4.x.x, but not 5.x.x)
~Allows updates to the most recent patch version."express": "~4.17.1" (compatible with 4.17.x, but not 4.18.x)
>=Specifies a minimum version."express": ">=4.17.1"
<Specifies a maximum version."express": "<5.0.0"
*Allows any version."express": "*"

Configurations for Publishing

FieldDescriptionExample
filesSpecifies which files should be included when the package is published."files": ["dist/", "index.js"]
mainEntry point for the module when it's required by another application."main": "index.js"
binDefine executable files that should be installed globally via npm install -g."bin": { "my-cli": "./bin/cli.js" }
typeSets the module type, either module (for ES modules) or commonjs."type": "module"
exportsDefines which module files should be exported when using import or require."exports": { ".": "./index.js", "./lib": "./lib/index.js" }
browserDefines a browser-compatible version of the module."browser": "browser.js"

Package Versioning and Hooks

FieldDescriptionExample
versionVersion number of the package, following semantic versioning (semver)."version": "1.0.0"
preversionHook that runs before a version is bumped."scripts": { "preversion": "npm test" }
versionHook that runs after the version is bumped but before it is committed."scripts": { "version": "npm run build" }
postversionHook that runs after the version is committed and tagged."scripts": { "postversion": "git push && git push --tags" }

Additional Fields

FieldDescriptionExample
bugsWhere to report issues related to the project."bugs": { "url": "https://github.com/user/repo/issues" }
contributorsList of contributors to the project."contributors": [{ "name": "Jane Doe", "email": "jane@example.com" }]
fundingProvides information on how to financially support the project."funding": "https://patreon.com/user"
workspacesList of directories for Yarn or npm workspaces, useful in monorepos."workspaces": ["packages/*"]
eslintConfigSpecify ESLint configuration settings directly in package.json."eslintConfig": { "extends": "eslint:recommended", "env": { "node": true } }

Common Custom Fields

FieldDescriptionExample
babelDefine Babel configuration in package.json instead of a separate file."babel": { "presets": ["@babel/preset-env"] }
jestConfigure Jest testing framework settings."jest": { "testEnvironment": "node" }
eslintConfigDefine ESLint settings."eslintConfig": { "extends": "airbnb" }
browserslistDefine the browsers that should be supported."browserslist": ["> 1%", "last 2 versions"]

Example package.json

json
{
  "name": "my-app",
  "version": "1.0.0",
  "description": "A simple Node.js app",
  "main": "index.js",
  "scripts": {
    "start": "node index.js",
    "test": "jest"
  },
  "author": "John Doe",
  "license": "MIT",
  "dependencies": {
    "express": "^4.17.1"
  },
  "devDependencies": {
    "jest": "^27.0.0"
  }
}