Home >Web Front-end >JS Tutorial >NPM:Node Package Manager
Let's explore the Node Package Manager (NPM). JavaScript developers working with React, Node.js, and similar technologies are likely already familiar with it. Essentially, NPM is a package manager for JavaScript, handling libraries, dependencies, and projects.
First, what is NPM? As the name suggests, npm is the Node Package Manager. It's a central repository for JavaScript packages.
To start a new project from scratch, begin with the command:
This initializes a Node.js project, tracking dependencies and scripts. The npm init
command prompts for package name, version, description, entry point, license, author, and more. This information populates the package.json
file, a JSON (key-value pair) representation of your application's details.
It looks like this:
To install packages, use npm install <package name>
. For example, installing Express:
This places Express within the node_modules
directory. node_modules
stores all installed packages.
node_modules
contains the project's dependencies. After installing Express, it resides within node_modules
:
Upon installation, package.json
's dependencies
section lists installed packages and their versions:
package-lock.json
tracks the precise versions of all dependencies:
In summary: NPM installs packages, while NPX executes them. This covers the basics of NPM.
The above is the detailed content of NPM:Node Package Manager. For more information, please follow other related articles on the PHP Chinese website!