[Traceability] What does npm do

Original link: https://zhuanlan.zhihu.com/p/24357770

Online npm tutorials mainly talk about how to install, configure and use npm, but they don't tell newcomers "why use npm".

Community
Programmers have had a community culture since ancient times:

Community means: people who have common occupations or interests, voluntarily organize together, and cooperate by sharing information and resources. Participants in virtual communities often discuss related topics online or visit certain websites.
Front-end programmers also have communities, and the largest front-end community in the world should be GitHub. The front end comes through GitHub

Share source code (online code repository) to
discuss issues (Issue list) to
collect learning resources and frequently visited websites (such as the high-quality Chinese front-end blog I collected)

One of the biggest benefits of joining the community is that you can use the code contributed by others, and you can also contribute code for others to use.

Sharing code
How does the front end share code?

In the era before GitHub, the front end shared code through URL

For example, if you want to use jQuery, then you can download jQuery by clicking on the link provided on the jQuery website and put it on your own website.

After the rise of GItHub, some people in the community also used the download function of GitHub:

Trouble
When a website relies on more and more code, programmers find this is a very troublesome thing:

Go to jQuery official website to download jQuery
Go to BootStrap official website to download BootStrap
Go to Underscore official website to download Underscore
……

Some programmers can't stand the bird, a programmer with three major virtues, Isaac Z. Schlueter (hereinafter referred to as Isaaz), gives a solution: use a tool to gather these codes together to manage it!

This tool is npm written by him in JavaScript (running on Node.js), the full name is Node Package Manager


The idea of ​​NPM for specific steps is roughly like this:

  1. Buy a server as a code repository (registry), put all the code that needs to be shared in it

  2. Send an email to notify jQuery, Bootstrap, Underscore authors to use npm publish to submit the code to the registry, and name them jquery, bootstrap, and underscore (note the case)

  3. If other people in the community want to use these codes, they can write jquery, bootstrap and underscore in package.json, then run npm install, npm will download the code for them

  4. The downloaded code appears in the node_modules directory and can be used at will.

These codes that can be used are called "packages", which is where the name of NPM comes from: Node Package Manager.

Development
Isaaz notified jQuery author John Resig, will he agree? This is not necessarily true, right.

Only when people in the community think "npm is a treasure", John Resig will consider using npm.

So how does npm become popular?

The development of npm is complementary to the development of Node.js.

Node.js was written by Ryan Dahl, an American programmer working in Germany. He wrote Node.js, but Node.js lacked a package manager, so he and the author of npm hit it off and got together, and finally Node.js built npm.

Everyone knows what happened later, Node.js became popular.

With the popularity of Node.js, everyone began to use npm to share JS code, so the jQuery author also released jQuery to npm.

So now, you can use npm install jquery to download the jQuery code.

Now using npm to share code has become standard on the front end.

Guess you like

Origin blog.csdn.net/weixin_43361722/article/details/114951772