What is NPM?

npm is the world’s largest software registry. Open source developers from every continent use npm to share and borrow packages, and many organizations use npm to manage private development as well.

npm consists of three distinct components:

Use the website to discover packages, set up profiles, and manage other aspects of your npm experience. For example, you can set up Orgs (organizations) to manage access to public or private packages.

The CLI runs from a terminal, and is how most developers interact with npm.

The registry is a large public database of JavaScript software and the meta-information surrounding it.

Get Started

To get started with npm, you can create an account on NPM website. After successfully creation of your account you can access your account as http://www.npmjs.com/~yourusername.

After you have created an account, next step is to install Node.js and NPM on your machine. After installation you can check if they are successfully installed by printing their version -

node -v
npm -v

Login

After you have successfully created an account and installed NPM on your machine you can login to NPM. To login type the following command -

npm login

Now you will be asked to provide UserName, Password and Email.

If you have 2FA (Two FActor Authentication) enabled then you will be promted to provide OTP from 2FA Authenticator app. However, after provided details, you will be logged in and you will get the following message -

Logged in as ssantanuberaa on https://registry.npmjs.org/.

Who Am I?

To know if you are successfully logged in, you can type the following command -

npm whoami

If you are logged in successfully, your UserName will be returned.

Changing Profile Information

Though you can do this through the NPM website, but you can also change your profile information using CLI.

See Profile Information

npm profile get

You will get the following information -

From the CLI you can change the following information -

To change the above information use the following syntax -

npm profile set prop value

Here prop is the property which are email, fullname etc. For example, to change your email address -

npm profile set email "yournew@email.com"

After that you will be prompted to provide your current password. Type the password to save the changes. If you have two-factor authentication enabled, you will be asked to provide OTP.

Though NPM allows us to change profile information using CLI, but it is always recommend to use the website as there are less chance of mistaken.

NPM Releases

There are two types of release in NPM -

Latest Release

The latest release of npm is the most recent stable version. When you install Node.js, npm is automatically installed. However, npm is released more frequently than Node.js, so to install the latest stable version of npm, on the command line, run:

npm install npm@latest -g

Next Release

The next release of npm is the most recent unreleased version of npm that is eventually released as the latest version. You may want to update your npm client to the next release to test your packages against it before latest is released. It means this version is unstable and might contain few bugs.

To update to the next release of npm, on the command line, run:

npm install npm@next -g

Depending on the development cycle, npm install npm@next -g may reinstall the latest release of npm.