What is Node package manager

Leave a Comment
After my first tutorials which is How to create server in node js i want to explain what is node package manager. Because after this tutorials we gonna look in how's node module works. So let's start with what is node package manager.

Node package manager is online repositories for node.js packages/modules. To install node package and do version management we have to use commands.
To check current NPM version on your computer type below command
$ npm --version

If you running old version than you can update easily by running below commnand
$ sudo npm install npm -g

How to install module using npm

Using below command you can install module in node
$ npm install 
Suppose you want to install express module of node then you have to type below command.
$ npm install express

Global vs local module installation

By default npm install local module to use local module you can use require method. To check which module is install locally you use below command
$ npm ls
To install global module you can use below command.
$ npm install  -g
You can use the following command to check all the modules installed globally
$ npm ls -g

Package.Json file

by typing below command you can generate package.json file
$ npm init
If you want to save you locally module in package.json file you can type below command
$ npm install --save express
Above command will save your module name and installed version in package.json file

Uninstall module

Use the following command to uninstall a Node.js module.
$ npm uninstall express

Updating a Module

Update package.json and change the version of the dependency to be updated and run the following command.
$ npm update express

Search a Module

Search a package name using NPM.
$ npm search express
Subscribe for more node js tutorials. I hope this will help you :D
Powered by Blogger.