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
.
- 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
- 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)
- Run the
pre-install
,install
andpost-install
scripts for itself and each dependencies. See Lifecycle Scripts.
Useful CLI Commands
- npm
JavaScript package manager
- npm access
Set access level on published packages
- npm adduser
Add a registry user account
- npm audit
Run a security audit
- npm bin
Display npm bin folder
- npm bugs
Bugs for a package in a web browser maybe
- npm build
Build a package
- npm bundle
Removed
- npm cache
Manipulates packages cache
- npm ci
Install a project with a clean slate
- npm completion
Tab completion for npm
- npm config
Manage the npm configuration files
- npm dedupe
Reduce duplication
- npm deprecate
Deprecate a version of a package
- npm dist-tag
Modify package distribution tags
- npm docs
Docs for a package in a web browser maybe
- npm doctor
Check your environments
- npm edit
Edit an installed package
- npm explore
Browse an installed package
- npm fund
Retrieve funding information
- npm help
Search npm help documentation
- npm help-search
Get help on npm
- npm hook
Manage registry hooks
- npm init
Create a package.json file
- npm install
Install a package
- npm install-ci-test
Install a project with a clean slate and run tests
- npm install-test
Install package(s) and run tests
- npm link
Symlink a package folder
- npm logout
Log out of the registry
- npm ls
List installed packages
- npm org
Manage orgs
- npm outdated
Check for outdated packages
- npm owner
Manage package owners
- npm pack
Create a tarball from a package
- npm ping
Ping npm registry
- npm prefix
Display prefix
- npm profile
Change settings on your registry profile
- npm prune
Remove extraneous packages
- npm publish
Publish a package
- npm rebuild
Rebuild a package
- npm repo
Open package repository page in the browser
- npm restart
Restart a package
- npm root
Display npm root
- npm run-script
Run arbitrary package scripts
- npm search
Search for packages
- npm shrinkwrap
Lock down dependency versions for publication
- npm star
Mark your favorite packages
- npm stars
View packages marked as favorites
- npm start
Start a package
- npm stop
Stop a package
- npm team
Manage organization teams and team memberships
- npm test
Test a package
- npm token
Manage your authentication tokens
- npm uninstall
Remove a package
- npm unpublish
Remove a package from the registry
- npm update
Update a package
- npm version
Bump a package version
- npm view
View registry info
- npm whoami
Display npm username