Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm install command - please explain

I am starting to learn React Native and I am very new to npm package manager. I read that npm can install packages localy or globaly but I am trying to understand what does that mean. I am reading this page https://docs.npmjs.com/getting-started/installing-npm-packages-locally, can someone explain to me what does this mean please.

If you want to depend on the package from your own module using something like Node.js' require, then you want to install locally, which is npm install's default behavior. On the other hand, if you want to use it as a command line tool, something like the grunt CLI, then you want to install it globally.

Since I am very new to npm, React Native, Node (never used it), I am confused by the very first sentence in this quote. What does it mean "my own module?

If I want to use CRNA, I guess, I would have to install it globally?

If I am to install a package, say CRNA locally or globally, where do I see it installed on my MacBook Pro?

like image 572
pixel Avatar asked Oct 24 '25 19:10

pixel


2 Answers

The difference between local and global install is that local install puts it into the node_modules directory of your project (this is what is referred to as "your own module") while global puts it into a system directory (the exact location depends on your OS, on OSX it should be /usr/local/lib/node_modules).

Basically:

  • Local install ties the installed module to your project: other projects on your computer do not get it but if your project is copied to another computer the module will be installed there too

  • global install ties it to your computer: you can use it on all of your projects on your computer but if your project is copied to another computer the installed module will not be there

And yes, CRNA should be installed globally as it is a general tool not a project's library dependence.

like image 176
dabadab Avatar answered Oct 26 '25 08:10

dabadab


When you install package globally npm install -g <package name> modules drops in {prefix}/lib/node_modules.

Locally - npm install <package name> - drops package in the current working directory.

If you are going to require module in your project you have to install it locally.

If you want to run in from command line you need to install it globally.

If you need more extenden explanation take a look

like image 36
Mikhail Katrin Avatar answered Oct 26 '25 09:10

Mikhail Katrin



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!