I was wondering if makes any sense to use in the npm install command the --global and the --save parameters all together. For example:
npm install gulp -g -s
As far as I know there is no package.json in the npm system folder, so I suppose the answer is "no", but I want to clear all doubt.
–save or -S: When the following command is used with npm install this will save all your installed core packages into the dependency section in the package. json file. Core dependencies are those packages without which your application will not give desired results.
You don't need --save anymore for NPM installs. This was long the golden standard to install a package and save it as a dependency in your project. Meaning if we didn't specify the --save flag, it would only get locally installed and not added to the package.
It's best to install locally when relying on a package from your module, such as Node. js. This is how npm install works by default. The grunt CLI package, for example, must be installed globally before it can be used as a command-line tool.
Tip: If you are using npm 5.2 or higher, we recommend using npx to run packages globally. Installing a package globally allows you to use the code in the package as a set of tools on your local computer.
The npm install
command does not support installing a module both globally and save it to the package.json in one step.
There is, however, a way to install a module globally indirectly. The package.json supports a preinstall property like so:
"scripts": {
"preinstall": "npm install -g gulp"
}
As soon as you execute npm install
, gulp will be installed globally. Please note that your current user then needs permission to write to your global node module directory.
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