In this article, we would like to show you the difference between global and local npm packages in Node.js.
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 are installed using:
npm install -g package-name
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:
const dotenv = require('dotenv');