npm

NPM, which stands for ‘Node Package Management’, is the built-in package manager for NodeJS. Although it was originally used as a way to download and manage node.js package dependencies, it has also become a tool used in front-end JavaScript.

Why do package management tools exist

Many languages have this package management tool. PIP for Python, Maven for Java, package management. Node.js was originally written by Ryan Dahl, an American programmer working in Germany. He wrote Node.js, but node.js lacked a package manager, so he hit it off with the author of NPM (Isaaz), and eventually NPM was built into Node.js

What can NPM do
1.Allows users to download third-party packages written by others from the NPM server for local use.2.Allows users to download and install command line programs written by others from the NPM server for local use.3.Allows users to upload their own packages or command-line programs to the NPM server for others to use. Behind NPM is a CouchDB-based database that records detailed information about each package, including author, version, dependencies, authorization information, and so on. One of its important functions is that it frees developers from the tedious work of package management (versions, dependencies, etc.) and focuses more on the development of features.Copy the code
NPM constitute
1.NPM consists of three separate parts:1.1.'the website' -- https://www.npmjs.com/, using the site to discover packages, set up configuration files, and manageOther aspects of the NPM experience. For example, organizations (organizations) can be set up to manage queries for public or private packages.1.2.'Registry'(registry) -- HTTPS://www.npmjs.com/signup, the registry is JavaScript software andA large public database of meta information around it (self-publishing the NPM package on the NPM website after registering an account)1.3.'Command line tools'(CLI) - a tool for developers to run NPM commands, which can be understood as running from the command line or terminal. Developers interact with NPM through the CLI.Copy the code
npm-cli
1.Of the three components on NPM-CLI is most exposed to in daily development, for example'npm install','npm ls'Wait, how does that work? Enter on the console' npm root -g'Something that could help us figure out the big picture`node_modules`The folder is printed out globally if you haven't done customization'node_modules'The premise, essentially, is to find the global`node_modules`It's as good as finding'node'CMD. If you are Linux, you can open the NPM file to view the contents. As you can see in the following image, this script helps us to call the global'node_modules'NPM /bin/npm-cli.js, NPM /bin/npm-cli.js'node npm-cli.js'. Open the'npm/bin/npm-cli.js'Look at the code below, where the variable NPM is passedvar npm = require('.. /lib/npm.js') The introduction is looking'/lib/npm.js'File find variable'commands'The set of instructions is pushed up to approximately'node_modules\npm\lib'Find the js file of the corresponding instruction under the file summary:'So far, we know that when we type NPM on the command line, we are executing npm-cli.js code in the Node environment.'

Copy the code
  • The node directory

  • Script code

  • npm-cli.js

  • Corresponding to the instructions

The installation
1.NPM does not require a separate installation. When installing Node, NPM is installed along with itCopy the code
  • Or NPM install NPM -g
1.Why can you install yourself? NPM itself is no different from any other Node module, it is just a JS running in the Node environmentCopy the code
update
1.NPM install npm@latest -g -- This will install the latest official beta version of NPM.2.NPM install npm@next -g -- To install future releasesCopy the code

Refer to the article

Basic usage and the principle of NPM | (10000 +) – long bytes long programming (mmbyte.com)

Vue Notes – NPM Tutorial – Jianshu.com