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.
npm install package-name
npm i package-name
- 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.
1. As normal dependency
Local installation in the current directory:
npm install package-name # or: npm install package-name-1 package-name-2 package-name-N
Before npm 5 we needed to use one of the variants:
npm install --save package-name npm install --save package-name-1 package-name-2 package-name-N npm install -S package-name npm install -S package-name-1 package-name-2 package-name-N npm i -S package-name npm i -S package-name-1 package-name-2 package-name-N
2. As development dependency (
Development dependencies are not built into the production package - they are needed only for development,
npm install -D package-name # or: npm install -D package-name-1 package-name-2 package-name-N
npm install --save-dev package-name # or: npm install --save-dev package-name-1 package-name-2 package-name-N