NPM cheat sheet

Instantiate NPM in the current directory

> npm init

Installing a new package.

> npm install package-name
> npm install package-name@version
> npm install package-name@latest

Installing a package only for development.

> npm install --save-dev package-name

Removing a package.

> npm uninstall package-name

Finding details of a package like description, maintainers, versions and dependencies.

> npm show package-name

List all packages installed into the current directory.

> npm ls

Running console commands that were installed through npm.

> npx command-name

Running build steps defined in NPM.

> npm start
> npm test
> npm run my-run-step
> npm help npm-scripts

Updating packages

Listing all packages that need updating.

> npm outdated

Update all packages that need updating.

> npm update

Semantic versioning:

  • Exact version: 3.3.1 or =3.3.1
  • At least minor version: ^3.3.1
  • Any minor version: 3.*
  • At least patch: ~3.3.1
  • Any patch: 3.3.*

Publishing a package

Publish a new version of a package.

> npm login
> npm publish

Posted on 26 Oct 18 by Helen Emerson (last updated on 26 Oct 18).
Filed under Uncategorized