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).
Related
Currently on version 8.5.3 and trying to downgrade to v6. The output seems fine but the result is still 8.5.3 even after restarting shells/OS:
PS C:\Users\myUser> npm install -g npm#latest-6
removed 384 packages, changed 3 packages, and audited 54 packages in 8s
found 0 vulnerabilities
PS C:\Users\myUser> npm --version
8.5.3
Powershell is being run with administration privileges, due to some errors when running it without privileges.
Instead of using:
npm install -g npm#latest-6
Use this:
npm install -g npm#6.14.16
And after that reboot (restart) your computer
for your version please use
npm install -g npm#6.14.4
for latest version please use
npm install -g npm#latest
It seems I have a path error, I can see proof the package installed, and I've tried it both globally and local, tried both with and w/o the -cli suffix, but zshell keeps complaining command not found
dr_frankenmiller#Bryans-MacBook-Pro ~ % npm install ganache-cli
npm WARN deprecated ganache-cli#6.12.2: ganache-cli is now ganache; visit https://trfl.io/g7 for details
added 1 package, and audited 102 packages in 11s
2 packages are looking for funding
run npm fund for details
9 vulnerabilities (8 moderate, 1 high)
To address issues that do not require attention, run:
npm audit fix
To address all issues (including breaking changes), run:
npm audit fix --force
Run npm audit for details.
dr_frankenmiller#Bryans-MacBook-Pro ~ % npm ls --depth=0
dr_frankenmiller# /Users/dr_frankenmiller
└── ganache-cli#6.12.2
dr_frankenmiller#Bryans-MacBook-Pro ~ % ganache-cli
zsh: command not found: ganache-cli
I might have done something bad, using a sudo rm -rf node_modules command to uninstall the package, was that dangerous to do? I reinstalled it globally and then tried running it again, and then zshell started complaining I wasn't authorized to run ganache. I tried the command sudo ganache, it asked me for password, and then responded again that command not found.
Can someone help me get back on track with my tutorial?
According to Ganache-CLI's instructions, it should be installed with:
npm install ganache-cli -g
I'd recommend installing the latest Ganache version rather than installing Ganache-CLI, though. Ganache-CLI is deprecated. Use
npm uninstall ganache-cli && npm install ganache -g
Ganache v7.0.0 and onward can be used in the CLI as well as programatically.
On another note, I strongly recommend against using sudo when installing anything via npm. This can give untrusted code the ability to run as admin on your system. Definitely a big security risk.
Just a follow up on difficulties I was having, I ended up using yarn to download and run ganache (MINUS the -cli suffix, -cli suffix now deprecated), yarn install ganache --global to install and then yarn ganache to run (no -cli necessary)
Here's how I found the solution for my specific use case. The bug came about when I was attempting to run a brownie deployment script. Run npm uninstall ganache-cli then run yarn global add ganache. Worked like a charm.
I just installed NPM. I don't know what to do. I've checked it all afternoon. Help me. Thank you. I've reinstalled it several times and tried many solutions. It's not easy.
I've tried the following
npm rebuild node-sass
npm install npm -g
sudo npm install -g npm
npm install -g npm
npm cache clear
npm cache verify
Npm install -g bower
Whatever I type, he answers me
Error: ENOENT: no such file or directory, mkdir 'E:\'
I'm really upset. Please help me
I've seen people say that re downloading can solve the problem. But clean up the registry. So I did it according to the plan, uninstalled node, downloaded regclean pro, and cleaned the registry. But it's still useless. I'll check the others. I sincerely look forward to your help.
The problem has been solved. I also tried to modify D: \ nodejs \ node_ Under modules \ NPM
. npmrc file.
Finally, modify the. Npmrc file under C: \ users \ administrator
prefix=D:\ node.js \node_ global
cache=D:\ node.js \node_ cache
registry= http://registry.cnpmjs.org/
python=python2.7
msvs_ version=2015
It's done
I want to delete npm from my system and start with a clean slate. So I run sudo apt remove npm.
Now, I called npm -v and it returned 6.13.7.
What dose that mean? is it possible that I have two or more installations of npm on my system? which one is considered "global"?
If I run whereis npm I get /usr/local/bin/npm and ls over there tells me its a soft link that points to /usr/local/lib/node_modules/npm
Should I simply rm * the folder and the link?
OK, took my risk and rm'ed the library and link. I did the trick. Now calling whereis npm returns an empty list and npm -v returns an error message.
So it probably was a path problem caused by improper installation process for node and npm in the first place.
What does the -S flag for npm mean? I see it referenced here but https://docs.npmjs.com/cli/install does not cover what the -S is.
npm i -S #types/google-apps-script
-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). However, --save or -S is totally unnecessary if you're using npm 5 or above since it's done by default.
The 'S' option is the Save option in npm. It adds the npm package to your dependencies for your project. It's the same as --save.