npm/Node.js introduction and quick installation-Linux CentOS

1.npm introduction

npm (Node Package Manager) is the package manager for Node.js. It is a tool for installing, managing and publishing JavaScript packages. npm enables developers to easily find and install existing JavaScript modules, as well as create and share their own modules.

Here are some of the main features and concepts of npm:

1.1. Package management:

npm provides an extensive package repository where developers can find and install JavaScript packages. These packages can be created by other developers or officially maintained packages. Developers can use npm installcommands to install specific packages and package.jsonmanage project dependencies through files.

1.2. Dependency management:

In a project, developers can use package.jsonfiles to define the project's dependencies. This file contains all packages and their version information required by the project. By running npm installthe command, npm will automatically install all the dependencies required for the project and save them in the project's node_modulesdirectory.

1.3. Version control:

npm uses Semantic Versioning to manage package versions. By specifying the major version number, minor version number, and revision number of the package, developers can flexibly control the use and update of the package. npm also supports locking exact versions of dependencies to ensure the same package version is used in different environments.

1.4. Script execution:

npm allows custom scripts to be defined and run in projects. By defining scripts in the field package.jsonin the file scripts, developers can use npm runthe command to run these scripts. These scripts can perform various tasks such as building, testing, deploying, etc.

1.5. Publishing and Sharing:

npm allows developers to publish the packages they create to npm's package repository for other developers to use and share. By running npm publishthe command, developers can publish their packages to npm and make them visible to other developers.

npm is a powerful and widely used tool that is indispensable for JavaScript developers. It simplifies the management and sharing process of JavaScript packages, allowing developers to develop and maintain JavaScript projects more efficiently.

2. Quickly install npm on CentOS

To install npm on CentOS, you can follow these steps:

2.1. Update system software packages:

Use the following command to update system packages to ensure you have the latest versions of packages installed.

sudo yum update

2.2. Install Node.js:

npm is the package manager for Node.js, so you first need to install Node.js. On CentOS, Node.js can be installed using NodeSource's sources. Execute the following command to add the NodeSource source:

curl -sL https://rpm.nodesource.com/setup_14.x | sudo bash -

This command will add sources for Node.js 14.x.

If you want to install a different version of Node.js, setup_14.xreplace with the corresponding version of the script.

2.3. Install Node.js and npm:

The commands to install Node.js and npm are as follows:

sudo yum install nodejs

After running this command, the yum package manager will automatically install Node.js and npm.

2.4. Verify installation:

After the installation is complete, you can run the following commands to verify the installation of Node.js and npm.

node -v
npm -v

If the installation is successful, the version numbers of Node.js and npm will be displayed.

Once installed, you can use npm for package management and building JavaScript applications on CentOS.

3. Reference

You can get more detailed information about installing npm on CentOS using the following official link:

3.1. Node.js official website:

https://nodejs.org

On the official Node.js website, you can find detailed documentation, download options, and installation instructions for Node.js and npm.

3.2. NodeSource official website:

https://nodesource.com

NodeSource is a company that provides Node.js distributions. They provide installation scripts and instructions for different Linux distributions. You can find detailed instructions for installing Node.js and npm on CentOS on their website.

Links to install Node.js and npm on CentOS found on the NodeSource official website:

  • NodeSource CentOS installation instructions: https://github.com/nodesource/distributions/blob/master/README.md#installation-instructions-for-centos

You can visit the above link for more official guides and instructions on installing Node.js and npm on CentOS.

Guess you like

Origin blog.csdn.net/holyvslin/article/details/132404237