What is global installation of dependencies in Node.js ?

29 Jul, 2021
The global installation of dependencies in Node.js is putting global packages in a single place in the system exactly where it depends on your setup, regardless of where you run the command npm install -g <package-name> to install dependencies.
Installing the local dependencies means the module will be available only for a project you installed in the same directory.
Global installing dependencies puts the module into your Node. js path, which is Operating System dependent) and will be accessible from any project without the need to install it separately for each project while doing the setup.
They allow us to use the packaging as a tool anywhere on the local computer.
Prerequisites:
Node JS: Node.js is an open-source and cross-platform runtime environment built on Chrome’s V8 JavaScript engine for executing JavaScript code outside of a browser. You need to recollect that NodeJS isn’t a framework, and it’s not a programming language.
React JS: React is a declarative, efficient, and flexible JavaScript library for building user interfaces. It’s ‘V’ in MVC. ReactJS is an open-source, component-based front-end library responsible only for the view layer of the application.
  Syntax:
run npm install -g <package-name>
Where g denotes a global mode of a variable.
Application: It is used to install packages globally in the system while making Node projects.
Path of Global Packages in the system: Global modules are installed in the standard system in root location in the system directory  /usr/local/lib/node_modules project directory.
Command to print the location on your system where all the global modules are installed. 
npm root -g
Output: 
C:\Users\Pallavi\AppData\Roaming\npm\node_modules
Example to illustrate how to install the package globally in the system.
Write this command in the console. 
npm install -g mit-license-generator
Output: 
How to check which packages are installed globally in the system. 
npm list -g
The output will be: 
Advantages:
We do not need to install a module every time when installed globally.
It takes less memory as only one copy is installed.
We can make .js scripts and run them anywhere without having a node_modules folder in the same directory when packages are installed globally.
Disadvantages:
when we are running a Node app other than a local machine, then it will give an error because it needs packages in package.json that i.e, local packages.
Globally deployed packages cannot be imported using require() in Node application directly.
 
rajeev0719singh
singghakshay
Node.js-Basics
NodeJS-Questions
Picked
Node.js
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
JWT Authentication with Node.js
Installation of Node.js on Windows
Difference between dependencies, devDependencies and peerDependencies
Mongoose Populate() Method
Mongoose find() Function
Top 10 Projects For Beginners To Practice HTML and CSS Skills
Difference between var, let and const keywords in JavaScript
How to insert spaces/tabs in text using HTML/CSS?
How to fetch data from an API in ReactJS ?
Differences between Functional Components and Class Components in React