Languages
[Edit]
EN

Node.js - npm global and local packages difference

0 points
Created by:
Maison-Humphries
311

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.

Note:

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.

Imports

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

require('package-name');

Practical example:

const dotenv = require('dotenv');
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