Q1:npm是什么?
npm是一个Javascript的包管理器。寻找,分享,重用成百上千的开发者创造的代码。用更强力的方式组合它们。
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.
一旦你依赖其他开发者的代码,npm让检查它们的任何升级变得简单,并且在他们完成时下载这些升级。
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.
这些重用的代码被称为包,或者模块。一个包只是一个包含一个或多个文件的目录,里面还由一个包含一些元数据的叫”package.json“的文件。一个典型的应用,比如一个网站,回依赖一打或者几百个包。这些包通常都很小。一个通常的想法,你创建一小块解决一个问题并且解决地很好的积木。这让你通过这些小的被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.
这样会由很多好处。通过引入专注特定问题领域的人开发的包,这让你的团队靠近领域之外的专业知识称为可能。但纪实你不会重用团队外的人的代码,使用这些基于方法的模块会帮助你的团队更好地协作,也会使跨项目重用代码车称为可能。
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.
你可以通过浏览npm的网站,寻找包们,来帮助你创建应用。当你浏览网站时,你会找到不同类型的包。你会找到大量的node包。npm始于node包管理器,因此,你会找到大量用于服务端的模块。也存在很多为了通过命令行使用而增加命令的包。此刻,你会找到用于浏览器前端的包。
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.
因此由于你已经对npm是做什么的有所了解,让我们谈谈它是怎么工作的。当人们谈论npm,他们会谈论三件中的一件。他们会谈论关于我会看到的网站。或者他们会谈论注册表,它是关与人们正在分享的包的巨大的数据库。又或者,他们会谈论客户端,当一个开发者决定分享他们的代码,他们会用安装npm客户端来把代码发布到注册表。一旦注册表里存在这个包的入口,其他的开发者就可以通过他们的npm客户端来从注册表安装包。该包的注册表入口也会映射到npm网站上一个独立的页面。
Q2:npm能做什么?
-
管理代码包之间的依赖关系
-
授权私人代码包
网友评论