Node.js & npm commands

npm, npx and nvm commands for Node.js projects: reinstalling dependencies, checking outdated packages, switching Node versions and scaffolding new apps.

14 commands

Node and npm versions

macOSWindowsLinux

Check which versions you’re running.

node -v && npm -v

Fresh reinstall of dependencies

macOSLinuxCareful

The classic fix for weird dependency errors.

rm -rf node_modules package-lock.json && npm install

Regenerates the lockfile, so versions may change within your semver ranges.

Clean install from the lockfile

macOSWindowsLinux

Deletes node_modules and installs exactly what package-lock.json says. Best for CI and reproducible builds.

npm ci

See outdated packages

macOSWindowsLinux

Current, wanted and latest versions of every dependency.

npm outdated

Update all packages to latest

macOSWindowsLinuxCareful

Bumps every version in package.json to the newest release.

npx npm-check-updates -u && npm install

Includes major versions that may have breaking changes. Commit first.

Why is this package installed?

macOSWindowsLinux

Shows which dependencies pulled it in.

npm explain

List global packages

macOSWindowsLinux

Everything installed with npm install -g.

npm ls -g --depth=0

Clear the npm cache

macOSWindowsLinux

Fixes some corrupted-download errors.

npm cache clean --force

Fix vulnerable dependencies

macOSWindowsLinux

Upgrades packages with known vulnerabilities where it’s safe to do so.

npm audit fix

Install and use the latest LTS Node

macOSWindowsLinux

Requires nvm (or nvm-windows).

nvm install --lts && nvm use --lts

Create a Next.js app

macOSWindowsLinux

Scaffolds a new Next.js project with prompts for TypeScript, ESLint and more.

npx create-next-app@latest

Create a Vite app

macOSWindowsLinux

Choose React, Vue, Svelte and more.

npm create vite@latest

Enable pnpm

macOSWindowsLinux

Turns on pnpm using Node’s built-in Corepack.

corepack enable pnpm

Run a package.json script

macOSWindowsLinux

Run npm run with no name to list available scripts.

npm run

Every command copies as plain, clean text: no curly quotes, no long dashes, no invisible characters.

Related guides