What does npm install -E mean? - npm

While studying Socket.io I encountered this npm command:
npm install -E socket.io-client#4.4.0
What does the -E tag mean?

npm documentation explains:
`-E, --save-exact`: Saved dependencies will be configured with an
exact version rather than using npm's default semver range
operator.
https://docs.npmjs.com/cli/v6/commands/npm-install

Related

is it neccessary to specify '-D' while using npm install?

for example, when I need to install webpack, usually we are supposed to use "npm i -D webpack", but if I use "npm i webpack" instead, there is no difference in my final bundle file, why we need to specify '-D'?
I think there is no differences between them, why not just use npm i?
npm i -D
npm i
As per the docs, npm install -D means you are installing the package as a devDependency and not a regular dependency.
How is this different?
When your app is deployed and your server runs the npm install step, it will only install the packages that are in dependency and not those in devDependency. Hence, we usually install things like eslint, typescript and such as devDependency and not regular depedency.
Reference
https://docs.npmjs.com/cli/v6/commands/npm-install

What does the npm -S flag mean?

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.

npm: Unhandled rejection Error: EISDIR: illegal operation on a directory, open ‘/Users/me/.npm/_cacache/content-v2/sha512/b3/da’

On my Mac, I just updated my working npm version from 5.6 to 6.9 thusly:
sudo npm i -g npm
Then I tried to install cordova like this:
sudo npm install -g cordova
And get
Unhandled rejection Error: EISDIR: illegal operation on a directory,
open '/Users/me/.npm/_cacache/content-v2/sha512/04/89'
npm ERR! cb() never called!
npm ERR! This is an error with npm itself. Please report this error at:
npm ERR! <https://npm.community>
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/me/.npm/_logs/2019-04-02T11_50_57_678Z-debug.log
I tried to downgrade thusly:
sudo npm install -g npm#6.4.1
but this fails with hundreds of lines like this:
npm WARN tar EISDIR: illegal operation on a directory, open '/tmp/npm-30934-a3ac319a/unpack-28da209e/bin/node-gyp-bin'
Unhandled rejection Error: EISDIR: illegal operation on a directory, open '/Users/me/.npm/_cacache/content-v2/sha512/99/72'
I also tried making sure the ownership was correct:
sudo chown -R $(whoami) ~/.npm
There are lots of posts of various EISDIR (error is a directory) problems for other directories (such as /usr/lib/modules), but no solutions seem to work.
Also, the npmrc file does not seem to exist. If I do:
npm config ls -l
globalconfig = "/usr/local/etc/npmrc"
userconfig = "/Users/me/.npmrc"
but neither file exists.
Note, I dont have homebrew, and didnt install it that way (I usually do manual installs).
I also tried this:
sudo npm cache clean -f
This did not help.
What else can I try? should I try deleting the ~/.npm dir?
Looking for a way to uninstall node, I found many old posts with long and sometimes conflicting lists of files to remove. Not sure if this will make it worse.
Any suggestions?
I think I have found a solution. I did the following:
installed node from the Mac pkg installer from https://nodejs.org/en/ This downgraded npm to 6.4.1 which is the version before EISDIR problems start apparently.
chmod -R 777 ~/.npm/_cacache // yes, this is not good
chown -R me ~/.npm/_cacache
After this, I could install cordova using "sudo npm install -g cordova" without errors.
I had the same problem when I upgraded to npm 6.9.0. You have to upgrade node to the last version:
brew reinstall node
At this time I have installed the latest available version for Mac OS Mojave (node: v11.14.0 and npm 6.9.0).
After node upgrade, I was able to install packages globally again.
Changing the ownership of files and then avoiding the use of sudo is a possible workaround for EISDIR with global installs using sudo. I suppose you have installed to default location folder:
sudo chown -R <user> ~/.npm
sudo chown -R <user> /usr/local/lib
sudo chown -R <user> /usr/local/bin
After this sequence, it worked to me.

What npm install -s mean?

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

What is the "-d" in "npm -d install"?

I've seen some posts that refer to running npm with a -d argument. For example, this issue refers to doing npm -d install coffee-script. There are a few other pages that also refer to this syntax, including the install instructions for at least one npm package.
But I've been unable to find any documentation for this -d argument. The docs for npm install make no mention of -d, nor does the npm FAQ, nor do any of the other documentation pages I've looked through.
Does the -d option do anything? If so, what?
It's a shortcut for --loglevel info
See the Shorthands and Other CLI Niceties section:
-d: --loglevel info