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
npm -S <package> with an uppercase -S or --save will install the package and save it to your dependencies in your package.
-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 ).
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.
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.
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.
@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).
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