Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Npm install --global" and "--save" together?

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.

like image 469
Nemus Avatar asked Jun 27 '16 14:06

Nemus


People also ask

Do I need to use the -- save with npm install?

–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.

Why do we not use -- save with npm install anymore?

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.

Should I install npm globally or locally?

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.

Should I install npm package globally?

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.


1 Answers

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.

like image 173
Steffen Langer Avatar answered Sep 17 '22 14:09

Steffen Langer