NPM basic scripts


Basic npm (Node Package Manager) commands for Windows users

Initialize a New Project

Terminal window
npm init

Creates a package.json file interactively.
Use npm init -y to create it with default settings.

Install Dependencies from package.json

Terminal window
npm install

Installs all dependencies listed in package.json.

Install a Package Locally

Terminal window
npm install <package-name>

or

Terminal window
npm i <package-name>

Example:

Terminal window
npm i express

Installs express in the current project.

Install a Package Globally

Terminal window
npm install -g <package-name>

Example:

Terminal window
npm i -g nodemon

Installs nodemon globally for system-wide use.

Uninstall a Package

Terminal window
npm uninstall <package-name>

or

Terminal window
npm rm <package-name>

Example:

Terminal window
npm uninstall express

List Installed Packages

Terminal window
npm list

or for global packages:

Terminal window
npm list -g --depth=0

Update a Package

Terminal window
npm update <package-name>

Example:

Terminal window
npm update express

Check for Outdated Packages

Terminal window
npm outdated

Clear npm Cache

Terminal window
npm cache clean --force

Run a Script (Defined in package.json)

Terminal window
npm run <script-name>

Example:

Terminal window
npm run start

Check npm Version

Terminal window
npm -v

Checks the installed version of npm.

Check Node.js Version

Terminal window
node -v

Checks the installed version of Node.js.