Overview And Functionality Of NPM (Node Package Manager)

In this article you will learn some answers to questions about NPM.

In this article you will learn some answers to questions about NPM.

  • What is NPM?
  • How to install NPM?
  • How to check NPM version?
  • What are the uses and advantages of NPM?
  • What is package-lock.json?
  • What is package.json?
  • How to install packages?
  • How to update local or globally packages?
  • How to uninstall packages?
  • How to create package.json?
  • How to search available packages on NPM?
NPM

What is NPM?

NPM stand for Node.JS Package Manager. NPM shipped with Node.js. NPM is one kind of middle main which connects projects with dependencies. NPM is written in Javascript.

With NPM you can install jquery, KnockoutJs, JqueryUI etc. As of this writing, there are a total number of 4,75,000 packages in NPM.

For more details check out this link:

https://docs.npmjs.com/getting-started/what-is-npm

Wikipedia Link

https://en.wikipedia.org/wiki/Npm_(software)

NPM

The above screenshot was taken from www.npmjs.com

How to install NPM?

To install NPM you should first install Node.js. While installing node.js, NPM will install automatically.

To install node.js please visit the following link,

https://nodejs.org/en/download/

How to check the NPM version?

There are two methods to check the version of npm:

To check the NPM version start DOS command prompt. Press key { START + R } and RUN window open and in RUN dialog box type CMD and press enter key.

Command

npm version

NPM

Command

npm -v

NPM

What are the uses and advantages of NPM?

Following are the uses and advantages of NPM:

  1. Manage local dependencies of project’s tools.
  2. Manage globally-installed project’s tools.
  3. Manage multiple versions of code and code dependencies.
  4. Download standalone tools you can use right away.
  5. NPM provides package-lock.json which displays all dependencies of the project.

What is PACKGE-LOCK.JSON? 

This stores file generated automatically when we request package updates (add/edit/delete).

This file displays all package details in tree format.

Sample view of NPM package-lock.json file.

NPM

What is package.json?

It's a complete list of project package dependencies. You can see a screenshot of package.json which was opened in a NOTEPLUS++ application.

You can see the names of dependency packages under the dependencies heading.

NPM

How to install a package?

You can install a package using a command.

Syntax

npm install <package name>

Example

npm install jquery

NPM

NPM

By default all packages go inside node_modules folders

How to update local or global packages?

You can update local or global packages.

To update local packages:  npm update

To update global packages: npm update -g

How to uninstall a package?

You can uninstall a package with a command.

Syntax

npm uninstall <package name>

Example

npm uninstall jquery

How to create package.json?

To create a new/renewed package.json file: 

Syntax

npm init

Example

npm init

As you press enter on <npm init> the command system will prompt you for the following details:

  1. Package Name
  2. Version
  3. Description
  4. Entry Point
  5. Test Command
  6. Git Repository
  7. Keywords
  8. Author
  9. License
NPM

NPM

You can see in the screenshot the package.json file was successfully created.

Package.json file content,

NPM

How to search available packages in NPM?

To search available packages in NPM there are the following commands:

Syntax

npm search <package name>

Example

npm search jquery tree

NPM