# Check npm version
npm --version
npm -v
# Update npm
npm install -g npm@latest
# Get help
npm help
npm help <command>
# Create package.json interactively
npm init
# Create with defaults
npm init -y
npm init --yes
# Create scoped package
npm init --scope=@myorg
# Install all dependencies from package.json
npm install
npm i
# Install a package (adds to dependencies)
npm install <package>
npm i <package>
# Install as dev dependency
npm install --save-dev <package>
npm i -D <package>
# Install globally
npm install -g <package>
# Install specific version
npm install <package>@<version>
npm install lodash@4.17.21
# Install from git
npm install git+https://github.com/user/repo.git
# Install without saving to package.json
npm install --no-save <package>
# Remove a package
npm uninstall <package>
npm un <package>
npm remove <package>
# Remove global package
npm uninstall -g <package>
# Remove dev dependency
npm uninstall --save-dev <package>
# Check for outdated packages
npm outdated
# Update all packages
npm update
# Update specific package
npm update <package>
# Update global packages
npm update -g
# List installed packages
npm list
npm ls
# List top-level packages only
npm list --depth=0
# List global packages
npm list -g --depth=0
# Show package info
npm info <package>
npm view <package>
# Show package versions
npm view <package> versions
# Run script from package.json
npm run <script>
npm run build
npm run test
# Common script shortcuts
npm start # runs "start" script
npm test # runs "test" script
npm stop # runs "stop" script
npm restart # runs "restart" script
# Run with arguments
npm run build -- --watch
# List available scripts
npm run
# Search for packages
npm search <keyword>
# View package details
npm view <package>
npm info <package>
# View package homepage
npm docs <package>
# View package repository
npm repo <package>
# Check for vulnerabilities
npm audit
# Fix vulnerabilities
npm audit fix
npm audit fix --force
# View cache folder
npm config get cache
# Clean cache
npm cache clean --force
# Verify cache
npm cache verify
# View all config
npm config list
npm config list -l
# Get config value
npm config get <key>
npm config get registry
# Set config value
npm config set <key> <value>
npm config set registry https://registry.npmjs.org/
# Delete config value
npm config delete <key>
# Edit config file
npm config edit
# Login to npm
npm login
npm adduser
# Publish package
npm publish
# Publish scoped package publicly
npm publish --access public
# Bump version and publish
npm version patch # 1.0.0 -> 1.0.1
npm version minor # 1.0.0 -> 1.1.0
npm version major # 1.0.0 -> 2.0.0
npm publish
# Unpublish (within 72 hours)
npm unpublish <package>@<version>
# Deprecate a version
npm deprecate <package>@<version> "message"
# Initialize workspace
npm init -w packages/my-package
# Install dependency in workspace
npm install <package> -w <workspace>
# Run script in workspace
npm run build -w <workspace>
# Run script in all workspaces
npm run build --workspaces
npm run build -ws
# List workspaces
npm ls --workspaces
# Run package without installing
npx <package>
npx create-react-app my-app
# Run specific version
npx <package>@<version>
# Run local package
npx <local-package>
# Clear npx cache
npx clear-npx-cache
# Check for issues
npm doctor
# Deduplicate dependencies
npm dedupe
# Rebuild native modules
npm rebuild
# Prune unused packages
npm prune
# Create package lock only
npm install --package-lock-only
# Install with exact versions
npm install --save-exact <package>
npm i -E <package>
# List all npm commands
npm help-search <term>