What is the real use of npm install --save

What is the use of npm install -g command?

npm is the world’s largest software registry. Open source developers from every continent use npm to share and borrow packages, and many organizations use npm to manage private development as well.

npm consists of three distinct components:

  • the website
  • the Command Line Interface (CLI)
  • the registry

use of npm install -g command?

The -g or --global argument will cause npm to install the package globally rather than locally.

Description

npm puts various things on your computer. That’s its job.

This document will tell you what it puts where.

  • Local install (default): puts stuff in ./node_modules of the current package root.
  • Global install (with -g): puts stuff in /usr/local or wherever node is installed.
  • Install it locally if you’re going to require() it.
  • Install it globally if you’re going to run it on the command line.
  • If you need both, then install it in both places, or use npm link.

 

 

  1. The -g directive tells npm to install the package in the global shared node_modules folder (usually where node is). This will also allow you to access the module from the command-line, as the bin is symlinked into a PATH folder (usually usr/local/bin). Check this url
  2. Download a npm package you specify with the argument, or inside your package.json file, along with it’s dependencies (from the npm repository host you define) inside a node_modules folder. (Or use an already existing local copy of it. see shrink-wrapping)
  3. Run the pre-installinstall and post-install scripts for itself and each dependencies. See Lifecycle Scripts.

 

 

Useful CLI Commands