Node JS Tutorial - Node Package Manager
In this tutorial, we will learn about the Node Package Manager (NPM), which is the core of any Node.js application. NPM provides a vast collection of libraries that serve as valuable tools for Node.js developers, speeding up the application development process.
Checking NPM Installation
To verify if NPM is installed on your system, run the following command:
npm –v
This will display the installed version of NPM on your console.
Using NPM to Install Modules
NPM includes a Command Line Client (CLI) that allows you to download and install modules. Let's see how to install a module using NPM.
Switch to the command prompt and install the Express module by typing:
npm install express
This will install the Express framework module.
Uninstalling Modules
If you want to uninstall a module, run the NPM uninstall command followed by the module name:
npm uninstall express
This will uninstall the Express module.
Searching for Modules
You can also search for modules using NPM. Let's search for the Express module:
npm search express
This will display the Express module details.
Creating a New Module
To create a new module, you need to generate a package.json file using NPM. This will create the basic skeleton of the package.json file.
Run the following command in the command prompt:
npm init
Press Enter and provide the required information about your module, such as its name, version, and description.
Once the package.json file is generated, use the NPM adduser command to register yourself with the NPM repository site using a valid email address. Finally, publish the module with the NPM publish command.
That's it! You have successfully learned how to use the Node Package Manager (NPM) to manage modules and create new ones.