EN
Node.js - npm global and local packages difference
0
points
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');