Home  >  Article  >  Web Front-end  >  nodejs npm installation tutorial

nodejs npm installation tutorial

王林
王林Original
2023-05-25 16:30:386466browse

Node.js is an open source JavaScript running environment that can run JavaScript code on the server side. Node.js has strong support for the ECMAScript standard and a wealth of modules and tools to help developers efficiently build, test and maintain web applications.

One of the most important tools in Node.js is npm (Node Package Manager), which is a module manager that can help developers easily install, upgrade and manage dependencies. This article will explain how to install Node.js and npm on Windows, Mac and Linux.

1. Install Node.js

Before you start installing npm, you need to install Node.js first. The official Node.js website provides installation programs for Windows, Mac and Linux.

Windows installation:

  1. Visit https://nodejs.org/en/download/ to download the Windows installer.
  2. Run the downloaded installer and follow the prompts to complete the installation.
  3. Enter node -v on the command line to check whether Node.js has been installed correctly. If the installation is successful, the version number of Node.js will be displayed.

Mac installation:

  1. Visit https://nodejs.org/en/download/ to download the Mac installer.
  2. Run the downloaded installer and follow the prompts to complete the installation.
  3. Enter node -v in the terminal to check whether Node.js has been installed correctly. If the installation is successful, the version number of Node.js will be displayed.

Linux installation:

  1. Open a terminal and enter the following command:

sudo apt-get update

sudo apt -get install nodejs

  1. Check whether Node.js has been installed correctly. Enter node -v in the terminal. If the installation is successful, the version number of Node.js will be displayed.

2. Install npm

After installing Node.js, npm will also be installed together. You can enter the npm -v command in the terminal to check whether npm is installed successfully.

If npm fails to install or needs to be upgraded, you can install or upgrade it through the following command:

npm install npm -g

This will install the latest version globally npm version.

3. Use npm

  1. Initialize a new npm project

Enter the project folder on the console and enter the following command:

npm init

Enter relevant information as prompted on the command line, such as project name, author, version number, etc.

  1. Install npm package

You can enter the following command on the command line to install the npm package:

npm install

For example, the command to install the Express framework is as follows:

npm install express

  1. Uninstall the npm package

You can enter the following command on the command line to Uninstall the npm package:

npm uninstall

For example, the command to uninstall the Express framework is as follows:

npm uninstall express

  1. Update npm package

You can enter the following command on the command line to update the npm package:

npm update

For example, the command to update the Express framework is as follows :

npm update express

  1. View npm package

You can enter the following command on the command line to view the installed npm package:

npm list

Alternatively, you can view the details of the specified module through the following command:

npm view

For example, view the details of the Express framework The command is as follows:

npm view express

Summary

This article introduces how to install Node.js and npm on Windows, Mac and Linux, and introduces how to use npm Manage dependencies. npm is a must-have tool for any developer who wants to build web applications using Node.js. Through the steps described in this article, I believe readers can successfully install Node.js and npm, and quickly master the basic usage of npm.

The above is the detailed content of nodejs npm installation tutorial. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn