Engineering

Node Package Manager (NPM) Commands

Node Package Manager (NPM) is two things, repositories for Node.js packages/modules and a command line utility to install Node.js packages, do version management and dependency management of Node.js packages.

NPM is bundled with the Node.js installation.

The NPM online repositories can be accessed here.

NPM Commands

Test a successful installation:

npm --version

or

npm -v

 

Interactively create a package.json file:

npm init

 

Install package:

npm install package_name

 

Install package globally:

npm install --global package_name

or

npm install -g package_name

 

Install package with a specific version (replace installed package with specified version):

npm install package_name@1.2.3

 

Uninstall package:

npm uninstall package_name

 

View installed packages:

npm list

or

npm ls

 

View globally installed packages:

npm list --global

or

npm ls -g

 

View outdated packages in your project:

npm outdated

 

Update all obsolete packages in your project:

npm update

 

Update specific obsolete package in your project:

npm update package_name

 

View package info:

npm view package_name

 

View the latest version of a package:

npm view package_name version

 

View all versions of a package:

npm view package_name versions

 

Start the Node server.js:

npm start

 

Install http-server module for web development

npm install http-server -g

Use this command to start an HTTP server on your local machine in the current directory: http-server.

 

 

To be continued…

Spread the knowledge