What is Node Package Manager?

Node Package Manager is a package manager for JavaScript language. It’s also called as npm. It is the default package manager for Node.js which is a javascript runtime environment.
It was created as an open-source project in 2009 to help javascript developers to share packages(code modules). npm has a large database of packages called npm registry. npm registry is a collection of packages.
Using npm command line client we can install and publish packages. npm.Inc company hosts and maintains the above operations.
npm is free to use. You can download and install npm packages without any registration.

How to install npm?

You can install npm using Node.js software. You can download and install Node.js from their official website https://nodejs.org/

Node.js

Updating npm:

You can update npm using the following command.

npm install @latest -g

-g flag updates npm globally.

npm – Commmand Line Client

You can use a command-line client for downloading and installing packages.

Example:

npm install

Dependency management:

npm also manages the dependencies of packages. package.json file contains dependencies of packages. Because of these dependencies, you can install all packages required in your project in one command. All packages defined in package.json can be installed using “npm install” command. package.json file must be written in JSON format.
You can create package.json file using the following command:

npm init –yes

–yes flag gives default values. You can also create a package.json file manually if you want.

Uninstalling packages:

You can uninstall the npm packages if you don’t want to use it anymore. You can uninstall npm package with the following command:

Example:

npm uninstall tinymce

Cache:

After installing any package, npm creates a copy of it in .npm directory of your path. So, next time if you are installing the same package then it copies from there. This .npm directory gets covered with old packages over time, so it is good to clean it from time to time.
You can clean npm cache with the following command:

npm cache clean –force

npm-audit:

You can scan your project for vulnerabilities and automatically install any compatible updates for those vulnerable dependencies.
If you want to scan your project for vulnerabilities without directly making changes you can do it with the following command:

npm audit

You can fix project vulnerabilities with the following command:

npm audit fix

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *