Open In App

What is npm CLI ?

Last Updated : 22 Mar, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

npm CLI is a combination of words where npm refers to Node Package Manager and CLI refers to the Command Line Interface . Using the command line we are trying to access the packages and dependencies of the NodeJS. npm CLI provides different commands for developers to install, delete, and manage.

npm CLI commands:

Here is a list of a few commands with their descriptions.

Command

Description

npm install

Install the dependencies that a project needs in package.json

npm install <package>

Install the specific package required for the project

npm update

It checks for updates and install the latest version

npm update <package-name>

It is used to update the latest version of that package

npm init -y

Initialise node by creating package.json file

npm ls

List all the packages in current project

1. npm install command:

This command is used to install all the dependencies needed for a project. It also installs their modules

npm install

Output:

Screenshot-from-2024-03-04-20-08-18-(1)-min-(1)

2. ‘npm install <packagename>’ command:

This command will only install the specified package mentioned. Other packages cant be install. Here we are installing the express modules.

npm install express

Output:

Screenshot-from-2024-03-04-20-23-01-(1)

3. ‘npm update’ command:

This command is used to update the packages that has outdated version. Updating packages periodically will ensure proper functionality without errors

npm update

Output:

Screenshot-from-2024-03-04-20-31-12-(1)

4. ‘npm init -y’ command:

This command is major one . By executing , it will create a package.json file . package.json file contains all the basic info about the project.

npm init

Output:

Screenshot-from-2024-03-04-20-37-22-(1)

5. ‘npm ls’ command :

This command is used to list all the packages in current project. If no files are found it returns empty

npm ls

Output:

Screenshot-from-2024-03-04-20-47-43-(1)

Features pf npm CLI:

  • It is used to install,uninstall,update and list the packages (Package Management)
  • It is used to initialise and run a project (Project Management)
  • It ensures consistency in Node projects by working with package-lock.json file.
  • It has better built in security. Vulnerabilities can be scanned through ‘npm audit’ command and are fixed periodically.

Benefits of npm CLI:

  • npm cli allows a faster interaction to install or create projects
  • Packages can be installed in less time
  • It allows the developer to customise the necessary changes required.


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads