NPM cheatsheet

Table of contents

  1. see NPM cheatsheet
  2. Package management
    1. Generate a plain old package.json using legacy init:
    2. Alias for npm install
    3. Install everything in package.json
    4. Install everything in package.json, except devDependecies
    5. Install a package
    6. Install a package as devDependency
    7. Install a package with exact
    8. Bump the package version
    9. Bump the major package version by 1 (1.2.3 → 2.0.0)
    10. Bump the minor package version by 1 (1.2.3 → 1.3.0)
    11. Bump the patch package version by 1 (1.2.3 → 1.2.4)
  3. Listing
    1. Lists the installed versions of all dependencies in this software
    2. Lists the installed versions of all globally installed packages
    3. Lists the latest versions of all dependencies in this software
    4. Lists only the dependencies in this software which are outdated
  4. Misc features
  5. Install names
  6. Updating
  7. NPM Ussage

see NPM cheatsheet


Package management

Generate a plain old package.json using legacy init:

npm init

Alias for npm install

npm i

Install everything in package.json

npm install

Install everything in package.json, except devDependecies

npm install --production

Install a package

npm install <package>

Install a package as devDependency

npm install --save-dev <package>

Install a package with exact

npm install --save-exact <package>

Bump the package version

npm version <version>

Bump the major package version by 1 (1.2.3 → 2.0.0)

npm version major

Bump the minor package version by 1 (1.2.3 → 1.3.0)

npm version minor

Bump the patch package version by 1 (1.2.3 → 1.2.4)

npm version patch

–save is the default as of npm@5. Previously, using npm install without –save doesn’t update package.json.

Listing

Lists the installed versions of all dependencies in this software

npm list	

Lists the installed versions of all globally installed packages

npm list -g --depth 0

Lists the latest versions of all dependencies in this software

npm view

Lists only the dependencies in this software which are outdated

npm outdated

Misc features

Install names

Updating


NPM Ussage

Usage:

npm install        install all the dependencies in your project
npm install <foo>  add the <foo> dependency to your project
npm test           run this project's tests
npm run <foo>      run the script named <foo>
npm <command> -h   quick help on <command>
npm -l             display usage info for all commands
npm help <term>    search for help on <term>
npm help npm       more involved overview

All commands:

    access, adduser, audit, bugs, cache, ci, completion,
    config, dedupe, deprecate, diff, dist-tag, docs, doctor,
    edit, exec, explain, explore, find-dupes, fund, get, help,
    hook, init, install, install-ci-test, install-test, link,
    ll, login, logout, ls, org, outdated, owner, pack, ping,
    pkg, prefix, profile, prune, publish, query, rebuild, repo,
    restart, root, run-script, search, set, shrinkwrap, star,
    stars, start, stop, team, test, token, uninstall, unpublish,
    unstar, update, version, view, whoami

Specify configs in the ini-formatted file:
    /Users/cjrequena/.npmrc
or on the command line via: npm <command> --key=value

More configuration info: npm help config
Configuration fields: npm help 7 config