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?
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)
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
Command
npm -v
What are the uses and advantages of NPM?
Following are the uses and advantages of NPM:
- Manage local dependencies of project’s tools.
- Manage globally-installed project’s tools.
- Manage multiple versions of code and code dependencies.
- Download standalone tools you can use right away.
- 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.
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.
How to install a package?
You can install a package using a command.
Syntax
npm install <package name>
Example
npm install jquery
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:
- Package Name
- Version
- Description
- Entry Point
- Test Command
- Git Repository
- Keywords
- Author
- License
You can see in the screenshot the package.json file was successfully created.
Package.json file content,
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