Install
npm install
Install all dependencies
Reads package.json and updates the lockfile if needed.
npm install <pkg>
Add a dependency
Saved under dependencies by default.
npm install -D <pkg>
Add a dev dependency
npm ci
Clean install from the lockfile
Deletes node_modules first and never rewrites the lockfile.
npm install <pkg>@<version>
Install a specific version or tag
A tag works too: <pkg>@latest or <pkg>@next.
npm install -g <pkg>
Install globally
npm uninstall <pkg>
Remove a dependency
npm install -E <pkg>
Save an exact version
Skips the ^ range in package.json.
npm ci --omit=dev
Install production deps only
npm install --package-lock-only
Update lockfile only
npm prune
Remove extraneous packages
npm dedupe
Flatten duplicate packages
npm rebuild
Rebuild native addons
Scripts & npx
npm run <script>
Run a package.json script
npm run
List available scripts
npm test
Run the test script
Shorthand for npm run test; npm start works the same.
npm start
Run the start script
npm run <script> -- <args>
Pass arguments to the script
Everything after -- goes to the script, not to npm.
npx <pkg> [args]
Run a package binary
Uses a local binary, else downloads it temporarily.
npm exec -- <cmd>
Run a command from the local tree
npm run <script> --if-present
Skip silently if missing
npm init -y
Create package.json with defaults
npm init <initializer>
Scaffold from a create-* package
npm init vite runs create-vite.
npm pkg set <key>=<value>
Edit package.json from the shell
Version & publish
npm version patch
Bump the patch version
Also commits and tags when in a git repo. Use minor or major
as needed.
npm version <x.y.z>
Set an exact version
npm version patch --no-git-tag-version
Bump without commit and tag
npm pack --dry-run
Preview the tarball contents
npm login
Log in to the registry
npm publish
Publish the package
npm publish --access public
Publish a scoped package publicly
Scoped packages default to private.
npm publish --dry-run
Check a publish without sending
npm publish --tag <tag>
Publish under a dist-tag
npm dist-tag ls
List dist-tags
npm deprecate <pkg>@<range>
"<msg>"
Mark versions deprecated
npm link
Symlink a local package
Run in the package, then npm link <pkg> in the consumer.
npm whoami
Show the logged-in user