Cheat Sheets Help

Npm

Basic Commands

Check NPM version

npm --version

Initialize a new Node.js project

npm init

Initialize a new Node.js project with default options

npm init -y

Install all dependencies from package.json

npm install

Install a specific package

npm install <package_name>

Install a package globally

npm install -g <package_name>

Install a package as a development dependency

npm install <package_name> --save-dev

Install a package at a specific version

npm install <package_name>@<version>

Uninstall a package

npm uninstall <package_name>

Uninstall a global package

npm uninstall -g <package_name>

Running Scripts

Run a script defined in package.json

npm run <script_name>

Start a project (runs the 'start' script)

npm start

Run tests (runs the 'test' script)

npm test

Run linting (if defined)

npm run lint

Package Management

List all globally installed packages

npm list -g --depth=0

List all locally installed packages

npm list --depth=0

Update all outdated local packages

npm update

Update a specific package

npm update <package_name>

Update global packages

npm update -g

Check for outdated packages

npm outdated

Audit dependencies for vulnerabilities

npm audit

Fix vulnerabilities

npm audit fix

Rebuild node modules

npm rebuild

Package Caching

Clear npm cache

npm cache clean --force

View npm cache

npm cache verify

Versioning & Publishing

Bump package version (major, minor, or patch)

npm version <major|minor|patch>

Publish a package to the npm registry

npm publish

Unpublish a package (for private packages)

npm unpublish <package_name>

Login to npm registry

npm login
Last modified: 08 September 2024