Rich
Rich

Reputation: 6573

Installing npm globally

Is it possible to install npm globally and is this a good idea?

I installed npm with the npm install command and was able to run npm start. Then after publishing my project to github I wanted to make sure it would run if someone cloned it, so I cloned it to a different directory on my machine. I then had to run npm install again to install the dependencies. Is it necessary to do this for each project you build locally or is it better and possible to install it globally on your machine?

Thanks

Upvotes: 7

Views: 15220

Answers (2)

safira
safira

Reputation: 115

To install a module from npm globally, you'll simply need to use the --global flag when running the install command to have the module install globally, rather than locally (to the current directory).

you can use command: npm install <module> --globalor npm install <module> -g

note: <module> is the name of the module you want to install globally

Upvotes: 2

Mohammad Sadiqur Rahman
Mohammad Sadiqur Rahman

Reputation: 5533

Command line for install npm globally--

npm install -g <package>

For more read from here.

In general, the rule of thumb is:

If you’re installing something that you want to use in your program, using require('whatever'), then install it locally, at the root of your project.

If you’re installing something that you want to use in your shell, on the command line or something, install it globally, so that its binaries end up in your PATH environment variable.

Details you can read here.

Upvotes: 12

Related Questions