Languages
[Edit]
EN

Node.js - install npm package locally

3 points
Created by:
Kenya-Spears
440

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:

npm install package-name

or shorter:

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.

Ā 

Installation variants

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 (devDependencies)

DevelopmentĀ dependenciesĀ areĀ not built into the production package - they are needed only for development,
e.g. nodemon, all @types/..., eslint, jest, typescript, etc.

npm install -D package-name

# or:

npm install -D package-name-1 package-name-2 package-name-N

or:

npm install --save-dev package-name

# or:

npm install --save-dev package-name-1 package-name-2 package-name-N
Native Advertising
šŸš€
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

ā¤ļøšŸ’» šŸ™‚

Join