Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What npm install -s mean?

Tags:

npm-install

I am installing some packages on NPM, sometimes I have to write -s and -g? What do they mean?

npm install -s socket.io
npm install -g xxxxxxx
like image 564
Y. Chen Avatar asked Feb 01 '19 00:02

Y. Chen


People also ask

What does S in npm install do?

npm -S <package> with an uppercase -S or --save will install the package and save it to your dependencies in your package.

What is the S flag in npm install?

-S is shorthand for --save , and it adds the package you're installing to the dependencies in your package. json file (which can be created with npm init ).

What is npm run S?

run-s command. A CLI command to run given npm-scripts sequentially. This command is the shorthand of npm-run-all -s . Usage: $ run-s [--help | -h | --version | -v] $ run-s [OPTIONS] <tasks> Run given npm-scripts sequentially. < tasks> : A list of npm-scripts' names and Glob-like patterns.

What does in npm install mean?

npm install (in Short: npm i) npm install , or npm i , is used to install dependencies: It will install all the dependencies. If you use ^ or ~ when you specify the version of your dependency, npm may not install the exact version you specified. npm install can update your package-lock.


2 Answers

npm -g <package> will install a package globally on your machine. Without the -g or --global flag, the package will be installed locally in the directory you were in when you ran the command.

npm -S <package> with an uppercase -S or --save will install the package and save it to your dependencies in your package.json, although I believe that is now the default behavior in current npm. I recommend reading the docs if you're unfamiliar with what's happening when you pass different options to npm.

like image 182
gpmetheny Avatar answered Sep 30 '22 12:09

gpmetheny


@gmmetheny answered the question about the global -g flag, but -s appears to silence the output of the command (at least in npm v7.0.15).

In other words, including -s (or --silent) in your npm install command means that it will have no output (only a newline):

> npm install -s example-package1 example-package2

This may be useful for running the command in a script.

Running the command without the -s flag echoes information about what was installed, e.g.:

> npm install example-package1 example-package2

npm WARN deprecated [email protected]: this library is no longer supported

added 160 packages, and audited 160 packages in 6s

14 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

You can diff the resulting directories created after running each variant of the command and you can verify that the effects are the same.

As @Max mentioned, this option is NOT mentioned in the npm docs (at least not in any prevalent location where a user might find it after a reasonable amount of searching).

like image 21
Everett Avatar answered Sep 30 '22 13:09

Everett