npm consists of three distinct components
- the website
- the Command Line Interface (CLI)
- the registry
Use the website to discover packages, set up profiles, and manage other aspects of your npm experience.
The CLI runs from a terminal, and is how most developers interact with npm.
The registry is a large public database of JavaScript software and the meta-information surrounding it.
在 npm registry 中包含了各种各样的 packages 和 Node moudules。
npm registry 中的最小元素是 package 和 module。
什么是 package ?
A package is a file or directory that is described by a package.json file. A package must contain a package.json file in order to be published to the npm registry.
那么 package 的格式是什么样的呢?
- a) A folder containing a program described by a package.json file.
- b) A gzipped tarball containing (a).
- c) A URL that resolves to (b).
- d) A <name>@<version> that is published on the registry with (c).
- e) A <name>@<tag> that points to (d).
- f) A <name> that has a latest tag satisfying (e).
- g) A git url that, when cloned, results in (a).
什么是 module ?
A module is any file or directory in the node_modules directory that can be loaded by the Node.js require() function.
为了可以被 Node.js 中 require() 函数引用,module 必须是如下格式:
- A folder with a package.json file containing a "main" field.
- A folder with an index.js file in it.
- A JavaScript file.
一般来说,npm 是一款用于管理包的工具。
参考: