Most Commonly Used npm Commands :
After installing node.js in development environment, we must be aware of some basic commands of node package manager npm. The below are the most commonly used ones:
Command 1:
Install package globally. Global packages are usually for executable commands.
This drops modules in {prefix}/lib/node_modules, and puts executable files in {prefix}/bin, where {prefix} is usually something like /usr/local. It also installs man pages in {prefix}/share/man, if they’re supplied.

$ npm install -g <package name>
# example
$ npm install -g express
# now we can use express to generate a new app
$ express new app

                            
If you’re installing something that you want to use in your shell, on the command line or something, install it globally, so that its binaries end up in your PATH environment variable.
Command 2:
Install package locally. Local packages are for the use of require in the app.
This installs your package in the current working directory. Node modules go in ./node_modules, executables go in ./node_modules/.bin/, and man pages aren’t installed at all.

$ cd /path/to/the/project
$ npm install <package name>
# example
$ npm install express
# now you can use `var express = require( 'express' );` in your app

                            
If you’re installing something that you want to use in your program, using require('whatever'), then install it locally, at the root of your project.
Command 3:
Uninstall global package.

$ npm uninstall -g <package name>
# example
$ npm uninstall -g express

                            
Command 4:
Uninstall local package.

$ cd /path/to/the/project
$ npm uninstall <package name>
# example
$ npm uninstall express

                            
Command 5:
Search package.

$ npm search <package name>
# example
$ npm search express

                            
Command 6:
List global packages.

$ npm ls -g

                            
Command 7:
List global packages detail.

$ npm ls -gl

                            
Command 8:
List local packages.

$ cd /path/to/the/project
$ npm ls

                            
Command 9:
List local packages detail.

$ cd /path/to/the/project
$ npm ls -l

                            
Command 10:
Update global packages.

$ npm update -g

                            
Command 11:
Update local packages.

$ cd /path/to/the/project
$ npm update

                            
About Me
Rahul Yadav

Rahul Yadav

Technical Architect

Kuala Lumpur, Malaysia

Connect Me:     

I'm a Full Stack Web Developer working in a MNC and passionate of developing modern web and mobile applications.

I have designed and developed CodephpOnline & CodephpOnline Wiki platform to expatiate my coding and technology learning experiences.

In my leisure time, I write technical articles on web development such as PHP, Laravel, CodeIgniter, Mediawiki, Linux, Angular, Ionic, ReactJS, NodeJS, AJAX, jQuery, Cloud and more.

Tag Cloud