NPM Common Commands
Here's a list of the most commonly used NPM commands when working on projects:
NPM Commands
Project Setup
npm init- Initialize a new npm projectnpm init -y- Initialize with default values
Package Management
npm install- Install all dependencies in package.jsonnpm install <package>- Install a package and add to dependenciesnpm install <package> --save-dev- Install as dev dependencynpm uninstall <package>- Remove a packagenpm update- Update all packagesnpm update <package>- Update specific packagenpm list- List installed packagesnpm outdated- Check for outdated packages
Cleaning & Troubleshooting
rm -rf node_modules- Delete node_modules directoryrm -rf node_modules && npm cache clean --force && npm install- Complete reset and reinstallnpm cache clean --force- Clear npm cachenpm audit- Check for vulnerabilitiesnpm audit fix- Automatically fix vulnerabilities if possible
Running Scripts
npm start- Run the start script defined in package.jsonnpm test- Run the test scriptnpm run <script-name>- Run a custom script defined in package.json
Package Publication
npm version patch/minor/major- Bump version according to semvernpm publish- Publish package to npm registry