📝 Edit on GitHub
Install packages
Note that npm i
is an alias for npm install
.
You must create a package.json
file with npm init
before you can run installs in a project.
See also the npm ci command which is simialr to npm install
but is more suitable for deploy pipelines.
Flags
-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.
Install by package name
Install and save as production dependency
This will add to dependencies
of package.json
after installing.
Install latest:
$ npm i PACKAGE
Example:
$ npm i foo
$ # Install multiple at once.
$ npm i foo bar baz
Install specific version:
$ npm i PACKAGE@VERSION
Example:
$ npm i foo@1.2.3
Install and save as dev dependency
Save to devDependencies
in package.json
using one of:
$ npm i PACKAGE --save-dev
$ npm i PACKAGE -D
Install from package file
Install prod and dev deps
$ npm i
Install only production dependencies
$ npm i --production
Or using --only
.
$ npm i --only=prod
$ npm i --only=production
Install only dev dependencies
$ npm i --only=dev
$ npm i --only=development
Install from GitHub
$ npm i USERNAME/PACKAGE_NAME
e.g.
$ npm install visionmedia/express#branch
Or add to package file:
- HTTPS
[ "git+https://github.com/visionmedia/express.git" ]
- SSH
[ "git+ssh://git@github.com/visionmedia/express.git" ]