Javatpoint Logo
Javatpoint Logo

npm Install Command

The Node Package Manager is known as npm. It serves as the Node JavaScript platform's package manager.

The largest software registry in the world is referred to as Npm. Npm is a sharing and displaying tool used by open-source developers worldwide.

Npm Parts

Npm is made up of three parts:

  • You can search for third-party packages on the website, create profiles, and maintain the packages.
  • You can communicate with npm through the command-line interface, sometimes known as the npm CLI, which is run from a terminal.
  • The registry is a sizable online repository for JavaScript source code.

Npm basic and Version Command

  • You use the npm command from a command to locate the npm Api on your computer:

The following image describes the output of the command.

npm Install Command

The command shown below, for instance, will show you your system's current npm version:

The following image describes the output of the npm version command.

npm Install Command

What is npm Capable of?

You can install a new package from the registry using npm. Additionally, npm enables you to find and share your fresh node packages. With npm, you will mostly use it for this purpose.

package.json

Typically, the root directory of npm project includes a file named package.json. Important data is contained in the package.json, a plain text file that npm utilizes to determine the project and manage dependencies.

Go to the project's root directory and use the command to generate the package.json file:

The following image describes the output of the npm command.

npm Install Command

When you use the npm init command, it will ask you for details about the project, such as:

  • A version of the package
  • package name
  • Git repository for the test command
  • Keywords
  • Author
  • License

It will accept the default values and continue to the next prompt if you press Return or Enter.

Utilize the following command if you want to use the default options:


npm Install Command

Install a New npm Package

The npm install command is worked to install a new package:

The package name must come after the npm install keywords in this command.

The following image describes the result of the npm command.

npm Install Command

You search for packages on the npm website to find them.

For instance, you can issue the following command to install the express package:

Keep in mind that the Node.js web framework express is quick. After the installation, you will notice that a brand-new directory named /node modules has been created beneath the project's root. This directory will house all of the newly installed modules.

The image gives the result of the npm command.

npm Install Command

You can see that npm installed express as well as its dependencies, as well as the dependencies of those dependencies, and so on, by expanding the /node modules directory.

The dependencies portion of the project's package.json file has been modified and now includes the express package, as shown in the example below:

The dependencies section will generally contain a list of any new packages you install. In this case, the express package with version 4.17.1 is one of the dependencies. Take note of the structural version control specification that Npm adheres to.

You can use the npm install command in the following shortened form to cut down on typing:

I indicate for install in this command. The image gives the result of the npm command.

npm Install Command

Installing a Package as a Requirement for Development

You may occasionally install a package that is only compatible with the development environment.

For instance, you could install the morgan package, which logs HTTP requests.

Use the npm install command with the ?save-dev option and the following syntax to accomplish this:

The output shows the operation done using the command line below the image.

npm Install Command

For illustration:

The output shows the operation done using the command line below the image.

npm Install Command

The morgan package will be downloaded and installed by this command. Additionally, it expands the bundle with a new part. devDependencies.json file should look like this:

  • In essence, the devDependencies should include the packages you utilize when developing.
  • You only need these packages while you are creating your application.
  • The dependencies, on the other hand, should include the packages your application will require.
  • In other words, your program will run with these required packages.
  • The npm install command can also obtain and install all the packages listed in the dependencies and devDependencies section.

npm Install Globally

Install a package on your system globally.

Use the following command to install a package on your system globally:

Or simply:


npm Install Command

You often install a package on your command line or shell when you wish to utilize it globally.

Installing a package is best if you wish to use it in your application.

Conclusion

For the Node Js/javascript platform, Npm serves as the package management. The command line helps to install npm step by step for development and operations. It helps to install npm and other related data in a single command line using a command prompt. The npm install for the javascript functionality in all web-related applications.







Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA