Home > OS >  What is difference between local and global Node package installation?
What is difference between local and global Node package installation?

Time:09-01

I ask this question because I have been installing nodemon with npm and I see the results of installing through the suggested command at first sight, at the right side of the screen:

npm i nodemon

It is different from the installation instructions you can read above, on the Installation section. There we see:

global installation:

npm install -g nodemon

install nodemon as a local project dependency:

npm install --save-dev nodemon

The thing is, what is difference between

npm i nodemon

and

npm install -g nodemon

When I use the first command it tells me typical "nodemon is not recognized as internal or external command, operable program or batch file". To solve it I must install globally.

CodePudding user response:

When you run npm i nodemon nodemon is installed as a local project dependency, to run nodemon on the CLI you would have to provide the pull path to it's installation, typically you would want to make this reference in your project's package.json file's scripts property, for instance:

{
    ...
    "scripts": { "nodemon": "nodemon index.js" },
    ...
}

This can then be executed by running npm run nodemon.

On the other hand running npm install -g nodemon or npm i -g nodemon installs nodemon on the global scope where it is referenced in your system PATH variable, that way you can easily call nodemon on the CLI and since it's full installation path is referenced in your system PATH variable it would execute like every other CLI command.

CodePudding user response:

Browser is made available to the current project (where it keeps all of the node modules in node modules) after local installation. It will not be available as a command that the shell can resolve until you install it globally with npm install -g module, in which case npm will install it in a location where your path variable will resolve this command. Typically, this is only good for using a module like so var module = require('module');

This documentation will help.

  • Related