What is the difference between NPM -g (global) install and NPM --save - npm

What is the difference between npm -g(global) install and npm --save?
First gulp install -g and --save first, then for other projects:
npm i gulp --save-dev Can I just use this command?
I don't know the basic difference between them?

npm -g will install packages globally (to npm cached folder), normally in AppData\Roaming\npm\node_modules if you're using Windows, while npm --save or --save-dev will install package directly to your node_modules directory in your project and add package to your packages.json for later purpose.

Related

How to install lodash.filter using npm?

I need to install lodash.filter to my Expo (React Native) project.
How should I do it using npm?
1.
npm i -g npm
npm i --save lodash.filter
npm i --save lodash.filter
I do not understand what npm i -g npm (it's updating something, but I think it will destroy my project).
$ npm i -g npm
$ npm i --save lodash
you can use second command.
npm i is the alias for the npm install and -g means gloabal
The -g or --global argument will cause npm to install the package globally rather than locally
npm install (in package directory, no arguments):
Install the dependencies in the local node_modules folder.
Just follow the command that are written in documentation it will be fine
The --save option instructed NPM to include the package inside of the dependencies section of your package.json automatically, thus saving you an additional step.

How to uninstall Gulp CLI from NPM globally?

I have the following package installed globally via npm:
+-- gulp-cli#2.0.1 (github:gulpjs/gulp-cli#4782b9a582ce7cc7e009073705a565b57d235332)
I have tried to uninstall it like so...
npm uninstall gulp-cli#2.0.1
But it does not remove it. How can I get this package removed from my global location?
I'm on npm version 6.1.0
Thanks to R. Wanjohi I figured it out for my machine. I had to do the following to get the global version of gulp cli off my machine:
npm rm -g gulp-cli
I was experiencing the same problem but when I used the following code, it worked:
npm rm -g gulp
You need to uninstall it globally (add the -g tag)
npm uninstall -g gulp-cli#2.0.1
Here is the npm docs: https://docs.npmjs.com/cli/uninstall.html
it's pretty simple, to uninstall a global package run
npm uninstall -g <package-name>
to verify run
npm ls -g --depth=0
for short videos

Command to use restoring npm packages

When I download a project from my repo with a package.json in its root, which command is the right one to use npm install or npm install restore?
The behaviour of npm install is
npm install without any argument will install all packages found in package.json in node_modules folder.
npm install <package_name> will install package_name. In your case will download restore package and will save it in node_modules folder. (https://www.npmjs.com/package/restore)
Just type:
npm i
From help:
>npm i -h
npm install (with no args, in package dir)
npm install [<#scope>/]<pkg>
npm install [<#scope>/]<pkg>#<tag>
npm install [<#scope>/]<pkg>#<version>
npm install [<#scope>/]<pkg>#<version range>
npm install <folder>
npm install <tarball file>
npm install <tarball url>
npm install <git:// url>
npm install <github username>/<github project>
aliases: i, isntall, add
common options: [--save-prod|--save-dev|--save-optional] [--save-exact] [--no-save]

how to update package.json after npm installl in a package

I'm writing a npm package, I'd like the package to update package.json file in the installed folder, say:
npm install mypackage
this installs mypackage, and also read the package.json in the folder where npm install is run, and write some entries, possible?
Thanks,
npm i -g npm-check-updates
npm-check-updates -u
npm install
or for a specific package, you may change dependency version and then
npm update --save

npm install grunt-uncss and npm install grunt uncss

pretty new to grunt and just trying to use uncss. Notice their is 2 way to install it with npm:
npm install uncss --save-dev and
npm install grunt-uncss --save-dev.
Besides one using phantom.js is their any difference ?? Pretty confused here.
Those are actually for two different packages:
npm install uncss --save-dev is for the uncss npm package.
npm install grunt-uncss --save-dev is for the grunt plugin for uncss
The difference between the two
One you can use with Grunt.js (grunt-uncss), the other you can't (without writing your own task that calls the module)