Node.js - npm global and local packages difference

0 points
Created by:

In this article, we would like to show you the difference between global and local npm packages in Node.js

Local packages

Local packages are installed using:

npm install package-name

They are installed in the directory where you run the npm install command and they are put in the node_modules folder under this directory.


It is recommended to install all packages locally.

Global packages

Global packages are installed using:

npm install -g package-name

Practical example:

npm install -g dotenv

They are all put into one place in your system depending on your setup, no matter where you run the npm install command.


To import both global packages and local packages we use the same syntax:


Practical example:

const dotenv = require('dotenv');
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
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.

❤️💻 🙂