EN
Node.js - install npm package locally
3 points
In this article, we would like to show you how to install npm package locally in Node.js.
As a local installation, we understand the packages are installed in the current project directory only.
Quick solution:
xxxxxxxxxx
1
npm install package-name
or shorter:
xxxxxxxxxx
1
npm i package-name
Notes:
- that approach is useful when the project uses specific packages versions (it is most common way to install packages in a project),
- go to last section to see how to install packages that are used only in developlemnt.
In this section, we present 2 installation variants: normal and development dependency installation.
Local installation in the current directory:
xxxxxxxxxx
1
npm install package-name
2
3
# or:
4
5
npm install package-name-1 package-name-2 package-name-N
Before npm 5 we needed to use one of the variants:
xxxxxxxxxx
1
npm install --save package-name
2
npm install --save package-name-1 package-name-2 package-name-N
3
4
npm install -S package-name
5
npm install -S package-name-1 package-name-2 package-name-N
6
7
npm i -S package-name
8
npm i -S package-name-1 package-name-2 package-name-N
Development dependencies are not built into the production package - they are needed only for development,
e.g. nodemon
, all @types/...
, eslint
, jest
, typescript
, etc.
xxxxxxxxxx
1
npm install -D package-name
2
3
# or:
4
5
npm install -D package-name-1 package-name-2 package-name-N
or:
xxxxxxxxxx
1
npm install --save-dev package-name
2
3
# or:
4
5
npm install --save-dev package-name-1 package-name-2 package-name-N