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.
這些重用的代碼被稱為包钳恕,或者模塊厘肮。一個(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ò)引入專注特定問(wèn)題領(lǐng)域的人開(kāi)發(fā)的包厦瓢,這讓你的團(tuán)隊(duì)靠近領(lǐng)域之外的專業(yè)知識(shí)稱為可能。但紀(jì)實(shí)你不會(huì)重用團(tuán)隊(duì)外的人的代碼啤月,使用這些基于方法的模塊會(huì)幫助你的團(tuán)隊(duì)更好地協(xié)作,也會(huì)使跨項(xià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ì)找到不同類型的包。你會(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)私人代碼包