Resources

Help

$ npm i --help
npm install (with no args, in package dir)
npm install [<@scope>/]<pkg>
npm install [<@scope>/]<pkg>@<tag>
npm install [<@scope>/]<pkg>@<version>
npm install [<@scope>/]<pkg>@<version range>
npm install <alias>@npm:<name>
npm install <folder>
npm install <tarball file>
npm install <tarball url>
npm install <git:// url>
npm install <github username>/<github project>

aliases: i, isntall, add
common options: [--save-prod|--save-dev|--save-optional] [--save-exact] [--no-save]

Flags

Some common or useful flags.

Flag Description
-D, --save-dev Save to dev dependencies. By default, installs are saved to prod dependencies without any flag (at least on newer NPM versions).
-G, -g, --global Install as a global dependency.
--production, --only=prod, --only=production Install only prod dependecies from package.json file.
-E, --save-exact Saved dependencies will be configured with an exact version rather than using npm’s default semver range operator. e.g. 1.2.3 instead of ^1.2.3 if doing npm install foo.

Install by package name

Install production dependency

No flags are needed.

$ npm install PACKAGE

This will add to dependencies of package.json after installing.

Example:

$ npm install foo
$ # Install multiple packages at once.
$ npm install foo bar baz

Install latest:

$ npm install PACKAGE@latest

Install specific version:

$ npm install PACKAGE@VERSION

Example:

$ npm install foo@1.2.3

Install and save as dev dependency

Save to devDependencies in package.json using one of:

$ npm install PACKAGE --save-dev
$ npm install PACKAGE -D

Install from GitHub

You can install the latest code on a GitHub repo easily, without it being published on the NPM registry.

$ npm install USERNAME/REPO_NAME

e.g.

$ npm install visionmedia/express
$ npm install visionmedia/express#develop

For clarity, you can add github:

$ npm install github:visionmedia/express

For more info, see the Registries page.

Install from package file

Install production and dev dependencies

$ npm install

Install only production dependencies

$ npm install --production

Or using the more verbose --only.

$ npm install --only=prod
$ npm install --only=production

Install only dev dependencies

$ npm install --only=dev
$ npm install --only=development

Install quietly

Set log level

$ npm install --loglevel warn

Downgrade

Note quotes to avoid a syntax error.

$ npm install 'PACKAGE<UPPER'

If you have say version 2 of a package but you need 1, you would do this.

e.g.

$ npm install '@automattic/vip@<2'

In this case, the result as package.json said I have version set at ^1.12.1.

If you simply do one of these:

$ npm install '@automattic/vip@1'
$ npm install '@automattic/vip@^1'

You’ll end up with 1 or ^1 version only and that lacks the other pieces.