I'm following examples that use the -g
flag when using npm install
but I can't figure out through the help system what the -g
flag is doing.
npm install -g. the -g flag is a shorthand for the global configuration which sets the package install location to the folder where you installed NodeJS. This is useful when you need to run the package from the command line instead of using require() and import it to your code.
The G (go) command moves to a specified line and displays it. It can move both backward and forward from the current line. The G command displays one line at a time.
npm install -g pm2 - pm2 will be installed globally. It will then typically be found in /usr/local/lib/node_modules (Use npm root -g to check where.) If you're using nvm, then your global modules may be in one of several places depending on the version of node you're using at the time.
js -g parameter installs Node. It can be used within the command line utilities such as npm or commands that come from globally installed modules.
-g
tells npm
to install the named module so that it's accessible globally.
But it's important to understand that -g
is typically only used for packages that provide command-line utilities so that their executable components are available in the system PATH
.
If you have multiple programs that require
the same package, each program should install the package locally. If you really want to share an installed package by installing it globally, you have to also use npm link
.
See the docs on the topic of globally installed packages here.
If you do npm help install
you will see that:
o npm install (in package directory, no arguments): Install the dependencies in the local node_modules folder. In global mode (ie, with -g or --global appended to the com- mand), it installs the current package context (ie, the current working directory) as a global package.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With