nodejs
is a popular javascript platform and framework which provides server and client-side libraries. What makes nodejs so successful is its package manager named npm
or nodejs package manager. npm provides easily install, update and remove packages and load libraries according to the application configuration.
Install Npm Package For Ubuntu, Debian, Mint, Kali
We can install npm
package with the apt
command where Ubuntu, Debian, Mint, Kali distributions support.
$ sudo apt install npm

Install Npm Package For Fedora, CentOS, RedHat
For yum
based distributions we will use yum
or dnf
command like below where we will install npm
package.
$ sudo yum install npm
OR
$ sudo dnf install npm

Print npm General Help Information
npm command provides different type of commands or options in order to manage nodejs packages. We can get general information about these command with the -h
option.
$ npm -h

Get Specific Command or Option Help For npm
In the previous example, we have listed generic information about the npm commands and options. We may need a more detailed help about these commands or options which can be listed with the COMMAND -h
. In this example, we will list detailed help about the search
command.
$ npm search -h

Search For A Packages with npm
We can search for a specific package for installation with the search
command or option. In this example, we will search the term angular
.
$ npm search angular

We can see that search results are printed and listed in a structured column. This search results will present the following information.
NAME
is the package full name likeangular
,angular-strap
etc.DESCRIPTION
is the info about the package what is it.AUTHOR
is the package creator’s name or team name.DATE
is the last time the package is updated.VERSION
is the version number of the package which is the latest.KEYWORDS
are some tags that describe and related to the package.
Install Single Package with npm
We can install packages with the install
npm command or options by providing the package full name. In this example, we will install the package named angular
.
$ npm install angular

We can see that after the package installation is complete the installed package name with is angular
and the version installed which is 1.7.8
are printed to the console.
Install All Project Dependencies in package.json with npm
package.json
provides the list of the packages which is required for a project. In order to run this project, the packages should be installed. npm
command can install packages listed in this package.json
easily.
{
"name": "node-js-sample",
"version": "0.2.0",
"description": "A sample Node.js app using Express 4",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"dependencies": {
"express": "^4.13.3"
},
"engines": {
"node": "4.0.0"
},
"repository": {
"type": "git",
"url": "https://github.com/heroku/node-js-sample"
},
"keywords": [
"node",
"heroku",
"express"
],
"author": "Mark Pundsack",
"contributors": [
"Zeke Sikelianos <zeke@sikelianos.com> (http://zeke.sikelianos.com)"
],
"license": "MIT"
}
We can simply use install
command which will automatically look for package.json
and install the required packages.
$ npm install
Update Packages with npm
Updating packages with the npm is easy as installing them. We will provide the package name we want to update to the update
command or option. In this example, we will update the package named angular
.
$ npm update angular
Update nmp

npm can install and update different JavaScript libraries. npm can also update itself like a normal package. We will use i
option and provide the package name as npm
like below.
$ npm i npm

We can see from the output that the current version is updated to the 6.9.0 .
Print Package Details with npm
npm package information can be listed with the info
or view
command. We will also provide the package name. In this example, we will list and print information about the angular
package.
$ npm info angular


We can see that the following information about the package is provided.
name
is the package full name.description
is short information about the package.latest
is the latest version of the package.readmeFilename
is the name of the README.homepage
is the official home page of the package.keywords
is related tags and keywords with the package.license
is a usage license.