No intro needed here, I'll get straight to the point.
Package Management
npm init
: Initializes a new npm project in the current directory and creates apackage.json
file.npm install <package>
: Installs a package and adds it to thedependencies
section ofpackage.json
.--save-dev
: Installs a package and adds it to thedevDependencies
section ofpackage.json
.--save-optional
: Installs a package and adds it to theoptionalDependencies
section ofpackage.json
.--only=dev
: Installs only the packages listed indevDependencies
.--only=production
: Installs only the packages listed independencies
.--no-save
: Installs a package without adding it todependencies
,devDependencies
, oroptionalDependencies
inpackage.json
.
npm update <package>
: Updates a package to the latest version.npm update
: Updates all packages to their latest version.npm uninstall <package>
: Uninstalls a package and removes it fromdependencies
,devDependencies
, oroptionalDependencies
inpackage.json
.npm prune
: Removes packages that are no longer listed independencies
,devDependencies
, oroptionalDependencies
inpackage.json
.npm pack
: Creates a tarball of the package, including all files in the package.npm version <update_type>
: Updates the version number in thepackage.json
file and creates a git tag. Theupdate_type
can be "patch", "minor", or "major" depending on the type of update.npm shrinkwrap
: Locks down the versions of a package's dependencies so that you can control exactly which versions of each dependency will be used when your package is installed.npm shrinkwrap --dev
: Also locks down the versions of a package's devDependenciesnpm shrinkwrap --prod
: Only locks down the versions of a package's dependencies, not devDependenciesnpm shrinkwrap --legacy-bundling
: Generates a shrinkwrap file that includes bundledDependencies, for npm versions < 5.npm dedupe
: Attempts to find and resolve duplicate packages in the current project.npm cache clean
: Clears the npm cache.npm publish
: Publishes the package to the npm registry so that it can be installed by others.npm link
: Symlinks a package folder. This is useful when developing a package locally and testing it in another project.npm unlink <package>
: remove the symlink for a local package
Script Management
npm run <script>
: Runs a script defined in thescripts
section ofpackage.json
.
Package Information
npm list
: Lists all installed packages.npm list --depth=0
: Lists only top-level packages.npm list --global
: Lists all globally installed packages.npm search <query>
: Searches for packages containingquery
in their name or description.npm outdated
: Lists packages that have updates available.npm info <package>
: Show detailed information about the package.npm explore <package>
: opens the package folder in the default file explorer.npm fund
: Lists the funding information of the dependencies of the current project.npm audit
: Check the current project's dependencies for security issues.npm audit fix
: Attempts to fix any found security issues in the current project's dependencies.npm outdated --global
: show the outdated global packages.npm update -g
: update all globally installed packages.npm ls
: list the packages and their dependencies installed in your project.npm ls -g --depth=0
: list the globally installed packages
Registry Management
npm login
: Logs in to the npm registry.npm logout
: Logs out of the npm registry.npm whoami
: Shows the currently logged-in user.npm adduser
: Creates a new user or logs in with an existing user.npm owner add <username> <package>
: Adds an owner to a package on the npm registry.npm owner ls <package>
: Lists the owners of a package on the npm registry.npm owner rm <username> <package>
: Removes an owner from a package on the npm registry.npm access <public|restricted> <package>
: Change the access level of a package to public or restrictednpm access ls-packages
: Lists all the packages you have access tonpm access ls-collaborators <package>
: lists the collaborators of a packagenpm access grant <read-only|read-write> <scope:package> <username>
: Grant read-only or read-write access to a package to a user.npm access revoke <scope:package> <username>
: Revoke a user's access to a package.
Configuration
npm config list
: Lists all the configuration settings.npm config set <key> <value>
: set a configuration valuenpm config delete <key>
: delete a configuration valuenpm config get <key>
: get the value of a specific configuration keynpm config edit
: opens the npm configuration file in the default editornpm prefix
: Display the path of the current global node_modules foldernpm root
: Display the path of the current package's foldernpm root -g
: Display the path of the global node_modules foldernpm profile get <key>
: get the value of a specific profile keynpm profile set <key> <value>
: set a profile valuenpm profile delete <key>
: delete a profile valuenpm profile list
: list all the profile values
Help
npm help
: Shows a list of all the npm commands.npm help <command>
: Shows detailed help for a specific command.npm help-search <keyword>
: Search the npm help documentation for the keywordnpm repo <package>
: Open the package homepage in the default browsernpm bugs <package>
: Open the package's issue tracker in the default browsernpm docs <package>
: Open the package documentation in the default browsernpm test <package>
: Run the test command defined in the package's package.jsonnpm stop <package>
: Run the stop command defined in the package's package.jsonnpm start <package>
: Run the start command defined in the package's package.jsonnpm restart <package>
: Run the restart command defined in the package's package.jsonnpm run-script <scriptname>
: run the script defined in the package.json file
While this is a pretty comprehensive cheatsheet, these are not ALL the commands and options available, also new commands and options may be added in future updates. Hope this cheatsheet may be helpful to you. Happy coding!