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
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 -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 some-pkg@1.2.3: 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).
npm install -g will install a package globally on your machine, means it will be available for all other user in computer. Without the -g or --global flag, the package will be installed locally in the directory you are currently working in, and will be available to you only.
npm install -s this will install package and also make and entry in package.json file. -s stands for --save. without -s, npm will install the package but will not make any entry in package.json.