npm in the node environment is the default package management and distribution tool; the full name of npm is "Node Package Manager", which has become an unofficial standard for publishing node modules. npm allows users to download third-party packages written by others from the NPM server to Use it locally, or allow users to upload packages or command line programs they write to the NPM server for others to use.
The operating environment of this article: Windows 10 system, nodejs version 16, Dell G3 computer.
npm is the default package manager for the JavaScript runtime environment Node.js.
The full name of NPM is Node Package Manager. It is a NodeJS package management and distribution tool and has become an unofficial standard for publishing Node modules (packages).
npm is a package management tool installed along with Nodejs. It can solve many problems in Nodejs code deployment. Common usage scenarios include the following:
Allow users to download third-party packages written by others from the NPM server for local use.
Allows users to download and install command line programs written by others from the NPM server for local use.
Allows users to upload packages or command line programs they write to the NPM server for others to use.
Since the new version of nodejs has integrated npm, npm was also installed before. You can also test whether the installation is successful by entering "npm -v". The command is as follows. If a version prompt appears, the installation is successful:
$npm-v2.3.0If you have an old version of npm installed, you can easily upgrade it through the npm command. The command is as follows:
$ sudo npm install npm -g/usr/local/bin/npm -> /usr/local/lib/node_modules/npm/bin/[email protected] /usr/local/lib/node_modules/npmIf it is a Window system, use the following command: npm install npm -g
Global installation vs. local installation
npm package installation is divided into two types: local installation (local) and global installation (global). Judging from the command line, the difference is only whether there is -g, such as
npm install express # Local installation npm install express -g # Global installationIf the following error occurs: npm err! Error: connect ECONNREFUSED 127.0.0.1:8087
The solution is: $ npm config set proxy null
Local installation
Place the installation package under ./node_modules (the directory where the npm command is run). If there is no node_modules directory, the node_modules directory will be generated in the directory where the npm command is currently executed.
Locally installed packages can be introduced through require().
Global installation
Place the installation package in /usr/local or the installation directory of your node.
Can be used directly from the command line.
If you want the functionality of both, you'll need to install it in both places or use npm link.
Recommended learning: "nodejs video tutorial"
The above is the detailed content of npm in the node environment. For more information, please pay attention to other related articles on this site!