Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between installing a package locally and globally using npm?

Tags:

node.js

npm

What is the difference between installing a package locally and globally using npm?

From my understanding:

Locally install: npm install <package>

  1. This package/module will find on your local node_modules folder and can only be usable for this project.
  2. This package/module can be accessible in using require("package") from code.
  3. This package/module can't be accessible in command line interface.

Globally install: npm install <package> -g

  1. This package/module will find on where node is installed in your machine like /usr/local and can be usable everywhere.
  2. This package/module can't be accessible in using require("package") from code.
  3. This package/module can be accessible in command line interface.

Please let me know. If I could misunderstand anything here. Thanks!

like image 655
Nazmul Basher Avatar asked Oct 24 '25 14:10

Nazmul Basher


1 Answers

You are correct except for 1 point.

The local packages exposing CLI utilities can be accessed from the command line. Newer versions of NPM create this .bin/ directory inside the local node_modules/.
Whenever you try to use a tool (let's take babel for example), if you use it from the command line and you have it installed in your project, npm will properly identify that package and run it's CLI for you.

Here's a useful article on the topic.

http://www.2ality.com/2016/01/locally-installed-npm-executables.html

like image 196
Adrian Oprea Avatar answered Oct 26 '25 04:10

Adrian Oprea



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!