npm文檔what_is_npm

Q1:npm是什么?

npm是一個(gè)Javascript的包管理器。尋找,分享,重用成百上千的開(kāi)發(fā)者創(chuàng)造的代碼。用更強(qiáng)力的方式組合它們。

If you've been working with Javascript for awhile, you might have heard of npm: npm makes it easy for Javascript developers to share the code that they've created to solve particular problems, and for other developers to reuse that code in their own applications.

2

Once you're depending on this code from other developers, npm makes it really easy to check to see if they've made any updates to it, and to download those updates when they're made.

一旦你依賴其他開(kāi)發(fā)者的代碼,npm讓檢查它們的任何升級(jí)變得簡(jiǎn)單,并且在他們完成時(shí)下載這些升級(jí)。

These bits of reusable code are called packages, or sometimes modules. A package is just a directory with one or more files in it, that also has a file called "package.json" with some meta data about this package. A typical application, such as a website, will depend on dozens or hundreds of packages. These packages are often small. The general idea is that you create a small building block which solves one problem and solves it well. This makes it possible for you to compose larger, custom solutions out of these small, shared building blocks.

這些重用的代碼被稱(chēng)為包,或者模塊。一個(gè)包只是一個(gè)包含一個(gè)或多個(gè)文件的目錄,里面還由一個(gè)包含一些元數(shù)據(jù)的叫”package.json“的文件。一個(gè)典型的應(yīng)用,比如一個(gè)網(wǎng)站,回依賴一打或者幾百個(gè)包。這些包通常都很小。一個(gè)通常的想法,你創(chuàng)建一小塊解決一個(gè)問(wèn)題并且解決地很好的積木。這讓你通過(guò)這些小的被fen'xiang組合更大、定制的解決方案。

There's lots of benefits to this. It makes it possible for your team to draw on expertise outside of your organization by bringing in packages from people who have focused on particular problem areas. But even if you don't reuse code from people outside of your organization, using this kind of module based approach can actually help your team work together better, and can also make it possible to reuse code across projects.

這樣會(huì)由很多好處。通過(guò)引入專(zhuān)注特定問(wèn)題領(lǐng)域的人開(kāi)發(fā)的包,這讓你的團(tuán)隊(duì)靠近領(lǐng)域之外的專(zhuān)業(yè)知識(shí)稱(chēng)為可能。但紀(jì)實(shí)你不會(huì)重用團(tuán)隊(duì)外的人的代碼,使用這些基于方法的模塊會(huì)幫助你的團(tuán)隊(duì)更好地協(xié)作,也會(huì)使跨項(xiàng)目重用代碼車(chē)稱(chēng)為可能。

You can find packages to help you build your application by browsing the npm website. When you're browsing the website, you'll find different kinds of packages. You'll find lots of node modules. npm started as the node package manager, so you'll find lots of modules which can be used on the server side. There are also lots of packages which add commands for you to use in the command line. And at this point you can find a number of packages which can be used in the browser, on the front end.

你可以通過(guò)瀏覽npm的網(wǎng)站,尋找包們,來(lái)幫助你創(chuàng)建應(yīng)用。當(dāng)你瀏覽網(wǎng)站時(shí),你會(huì)找到不同類(lèi)型的包。你會(huì)找到大量的node包。npm始于node包管理器,因此,你會(huì)找到大量用于服務(wù)端的模塊。也存在很多為了通過(guò)命令行使用而增加命令的包。此刻,你會(huì)找到用于瀏覽器前端的包。

So now that you have an idea of what npm can do, let's talk about how it works. When people talk about npm, they can be talking about one of three things. They could be talking about the website, which we've just been looking at. Or they could be talking about the registry, which is a big database of information about packages that people are sharing. Or the third thing they could be talking about is the client: when a developer decides to share their code, they use the npm client which is installed on their computer to publish that code up to the registry. And once there's an entry for this package in the registry, then other developers can use their npm clients to install the package from the registry. The entry in the registry for this package is also reflected on the website, where there's a page dedicated to this new package.

因此由于你已經(jīng)對(duì)npm是做什么的有所了解,讓我們談?wù)勊窃趺垂ぷ鞯摹.?dāng)人們談?wù)搉pm,他們會(huì)談?wù)撊械囊患K麄儠?huì)談?wù)撽P(guān)于我會(huì)看到的網(wǎng)站?;蛘咚麄儠?huì)談?wù)撟?cè)表,它是關(guān)與人們正在分享的包的巨大的數(shù)據(jù)庫(kù)。又或者,他們會(huì)談?wù)摽蛻舳耍?dāng)一個(gè)開(kāi)發(fā)者決定分享他們的代碼,他們會(huì)用安裝npm客戶端來(lái)把代碼發(fā)布到注冊(cè)表。一旦注冊(cè)表里存在這個(gè)包的入口,其他的開(kāi)發(fā)者就可以通過(guò)他們的npm客戶端來(lái)從注冊(cè)表安裝包。該包的注冊(cè)表入口也會(huì)映射到npm網(wǎng)站上一個(gè)獨(dú)立的頁(yè)面。

Q2:npm能做什么?

  • 管理代碼包之間的依賴關(guān)系

  • 授權(quán)私人代碼包

Q3 : npm的特點(diǎn)?

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容