Installing a Package Globally

To install a package globally (accessible by all projects in system), add an extra -g tag in syntax used to install the package. Installing nodemon package globally.

Syntax to Install Packages Globally:

npm install nodemon -g

Installing nodemon package globally

Node JS NPM

NPM (Node Package Manager) is the default package manager for Node and is written entirely in JavaScript. Developed by Isaac Z. Schlueter, it was initially released in January 12, 2010. NPM manages all the packages and modules for Node and consists of command line client npm.

NPM gets installed into the system with installation of Node. The required packages and modules in Node project are installed using NPM. A package contains all the files needed for a module and modules are the JavaScript libraries that can be included in Node project according to the requirement of the project.

NPM can install all the dependencies of a project through the package.json file. It can also update and uninstall packages. In the package.json file, each dependency can specify a range of valid versions using the semantic versioning scheme, allowing developers to auto-update their packages while at the same time avoiding unwanted breaking changes.

Table of Content

  • Some facts about NPM
  • Installing NPM
  • Checking and updating npm version
  • Creating a Node Project
  • Installing Packages
  • Using a package in Node
  • Installing a Package Globally
  • Controlling where the package gets installed
  • Save Directory of Installed Modules
  • Uninstalling Packages
  • Using Semantic Versioning to manage packages

Similar Reads

Some facts about NPM:

At the time of writing this article, NPM has 580096 registered packages. The average rate of growth of this number is 291/day which outraces every other package registry. npm is open source The top npm packages in the decreasing order are: lodash, async, react, request, express....

Installing NPM:

To install NPM, it is required to install Node.js as NPM gets installed with Node.js automatically....

Checking and updating npm version

Version of npm installed on system can be checked using following syntax:...

Creating a Node Project:

To create a Node project, npm init is used in the folder in which user want to create project. The npm command line will ask a number of questions like name, license, scripts, description, author, keywords, version, main file etc. After npm is done creating the project, a package.json file will be visible in project folder as a proof that the project has been initialized....

Installing Packages:

After creating the project, next step is to incorporate the packages and modules to be used in the Node Project. To install packages and modules in the project use the following syntax:...

Using a package in Node

To use express in the Node, follow the below syntax:...

Installing a Package Globally

To install a package globally (accessible by all projects in system), add an extra -g tag in syntax used to install the package. Installing nodemon package globally....

Controlling where the package gets installed:

To install a package and simultaneously save it in package.json file (in case using Node.js), add –save flag. The –save flag is default in npm install command so it is equal to npm install package_name command....

Save Directory of Installed Modules

NPM installs the dependencies in local mode (Default) which go to the node_modules directory present in the folder of Node application. To see all the locally installed modules use npm ls command....

Uninstalling Packages:

To uninstall packages using npm, follow the below syntax:...

Using Semantic Versioning to manage packages:

...