Npm Update Library and Npm List

JavaScript code can be run independently of a browser using the open-source, cross-platform Node.js runtime environment.

The "npm" represents "Node Package Manager". The Node.js package manager is used to install various internet packages as well as dependencies into a local environment using a command-line tool.

It is a requirement to determine whether Node.js is installed on the local machine before executing instructions with npm. If this is untrue, install the most recent version of Node.js by visiting this link: https://nodejs.org/en/download/.

Establishing a test project

Let's begin by setting up a test project and a few packages.

  • Initially, use the following command to install npm in a project using the command line.
  • for global installation, use the below command,
  • for local installation, use the below command

The command line shows the result using the command prompt below the image.

Npm Update Library and Npm List
  • First, execute the npm init command in a new directory created for it named npm-demo:

The command line shows the result in the below image.

Npm Update Library and Npm List
  • Secondly, execute the following commands to install the express package:

The command line works using a command prompt.

Npm Update Library and Npm List
  • Third, Execute the mongoose packages

The command line works with the command prompt.

Npm Update Library and Npm List
  • Forth, use the npm install command with the -save-dev argument to install a morgan package as a developmental dependency:

The above command line works using the command prompt.

Npm Update Library and Npm List

npm list command introduction

Now let's look at the npm user-installed package list. In the current working directory where npm is installed, you must use the "npm-list" command. Every installed package will be set up in a structure that resembles a tree.

Npm list commands

The current project's installed packages and required dependencies are output as a tree structure to the stdout by the npm list command:

The command line works using a command prompt.

Npm Update Library and Npm List

The npm list command is available in a simpler form called npm ls. This command shows a list of the npm package with smaller commands.

Output

The following output image shows the result of the npm list.

Npm Update Library and Npm List

Npm extra information

The output will also contain extra information using the following commands.

Or

Output

The following output image shows the result of the npm information.

Npm Update Library and Npm List

Defined depthUse npm

A listing of packages with a defined depthUse npm list with the --depth flag to set a limit on the depth of the dependency tree. This command shows the root of the tree packages.

The sample below displays every installed package without any dependencies:

Output

The following image shows the result of the command line.

Npm Update Library and Npm List

Listing the dependencies for packages

The --prod or --production flag is used in the following way to display only the dependency tree for packages that are dependencies:

Output

The following image shows the result of the command line.

Npm Update Library and Npm List

Keep in mind that --production is an alias for --prod. The --prod and --depth flags can be used together as follows:

Output

The following image shows the result of the command line.

Npm Update Library and Npm List

Packages listed in devDependencies

By using the npm list command with the --dev or --development flag, you can display the dependency tree for packages in the devDependencies:

Or

  • The -dev or -dev can replace with the --development.

Output

The following image shows the result of the command line.

Npm Update Library and Npm List

How to Verify Every Global Package

Each npm package has a specific set of dependencies that enables them to function smoothly and effectively. You have two choices when viewing your npm list global packages.

All of your packages may be easily checked in the global space.

Alternatively, you can just examine the system's top-level packages that you have manually installed.

The command is the same for both procedures, yet the outcomes differ.

  • You can use the npm list command with the "-g" flag, where "g" stands for global, to examine the list of npm global packages and their dependencies.
  • Using the --global flag on the npm list command, you may list the global packages:

Output

The following image shows the result of the command line.

Npm Update Library and Npm List

Conclusion

Here, we can get the npm available version, npm list, and other packages. We can show the dependency and global packages using the simple command line.






Latest Courses