npm

the package manager for JavaScript

NPM package comparison

Packages

Essential packages

Usage

Create a package.json file.

npm init -y

Specifics of npm's package.json handling.

{
  "name": "name",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "clean:dir": "rm -rf node_modules",
    "clean:cache": "npm cache clean --force",
    "clean": "npm run clean:dir && npm run clean:cache",
    "reinstall": "npm run clean && npm install"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}

Commands

Install a package.

npm install
npm i

Package will appear in your devDependencies.

npm install --save-dev <package...>
npm i -D <package...>

This uninstalls a package, completely removing everything npm installed on its behalf.

npm uninstall

This runs the build command from a package's "scripts" object.

npm run build

This command will check the registry to see if any (or, specific) installed packages are currently outdated.

npm outdated

Upgrade all the packages in your package.json to the latest version.

npm install -g npm-check-updates
ncu -u
npm update
npm install

Bump a package version.

npm version [<newversion> | major | minor | patch | premajor | preminor | prepatch | prerelease | from-git]

Command Reference

Integration with visual studio code

  • npm
    npm support for VS Code.

  • npm Intellisense
    Visual Studio Code plugin that autocompletes npm modules in import statements.