亚洲视频二区_亚洲欧洲日本天天堂在线观看_日韩一区二区在线观看_中文字幕不卡一区

公告:魔扣目錄網為廣大站長提供免費收錄網站服務,提交前請做好本站友鏈:【 網站目錄:http://www.430618.com 】, 免友鏈快審服務(50元/站),

點擊這里在線咨詢客服
新站提交
  • 網站:51998
  • 待審:31
  • 小程序:12
  • 文章:1030137
  • 會員:747

npm 包管理器

npm is a package manager that comes bundled with Node. Contrary to popular belief npm is not an acronym. According to the npm FAQ It provides an easy way to install modules for your Application, including all required dependencies. Node relies on the package.json specification for package configuration. It's common to use npm to pull in all of your project's open source JAVAScript requirements on the server-side, but there is also a movement forming to use npm to pull in open-source dependencies for the client-side, as well.

npm 是一款包管理器,隨 Node 捆綁發布。人們普遍以為 npm 是一個首字母縮寫詞,但其實不是。據 npm 的 FAQ 所說,它提供了一種簡易的方式來為你的應用程序安裝模塊,并且包括所有必要的依賴模塊。Node 依靠 package.json 規約來進行包的配置。在服務器端 JavaScript 項目中,使用 npm 來拖入所需的開源依賴庫是很普遍的做法;但最近也有人開始把它用于客戶端項目。

(譯注:好吧,八卦一下。npm 實際上就是“Node Package Manager”的縮寫,沒有第二種含義,你不用懷疑自己的智商。只不過 npm 官方的這些人否認了這一點,并且強調這個詞應該全小寫,具體可以參見 npm 的 FAQ,看起來很二很扯淡。不過實際上背景是這樣的,軟件業內有一股另類風氣,就是開發者很熱衷于把自己的軟件名解釋為一個很扯的遞歸縮寫,比如 LAME 就聲稱自己是“Lame Aint an MP3 Encoder”的縮寫,可是地球人都知道你丫就是啊!又比如 GNU 聲稱“GNU's Not Unix”,一定要與 UNIX 劃清界限,等等等等。于是,npm 官方的這群奇異動物借自己的項目對此吐槽了一把。你可能注意到了,本文作者也提到了“npm 的 FAQ”這個梗。)

Directives

指令

npm has a number of well documented directives, but for the purposes of this book, you'll only need to know the ones you'll commonly need to modify in order to get your typical app up and running:

npm 有很多指令,相關文檔也很詳盡,不過對本書來說,只需要向你介紹其中最常修改的那些指令,就足以讓一個常規應用跑起來了:

  • name - The name of the package.
  • version - Package version number. npm modules must use semantic versioning.
  • author - Some information about the author.
  • description - A short description of the package.
  • keywords - Search terms to help users find the package.
  • main - The path of the main package file.
  • scripts - A list of scripts to expose to npm. Most projects should define a "test" script that runs with the command npm test. Use it to execute your unit tests.
  • repository - The location of the package repository.
  • dependencies, bundledDependencies - Dependencies your package will require().
  • devDependencies - A list of dependencies that developers will need in order to contribute.
  • engines - Specifies which version of Node to use.
  • name - 包的名稱。
  • version - 包的版本號。npm 模塊必須使用語義化版本管理方式。
  • author - 有關作者的信息。
  • description - 包的簡要描述。
  • keywords - 可以幫助用戶找到這個包的搜索關鍵詞。
  • main - 包的主文件的所在路徑。
  • scripts - 需要暴露給 npm 的腳本的清單。大多數項目應該定義一個 "test" 腳本,可以通過 npm test 命令來運行。用這個命令來執行單元測試。
  • repository - 包的代碼倉庫所在的位置。
  • dependencies, bundledDependencies - 你的包需要 require() 的依賴庫清單。
  • devDependencies - 開發者所需要的依賴庫清單,以便他們貢獻代碼。
  • engines - 指定適用的 Node 版本。

If you want to build a node app, one of the first things you'll need to do is create a server. One of the easiest ways to do that is to use Express, a minimal application framework for Node. Before you begin, you should look at the latest version available. By the time you read this, the version you see here should no longer be the latest:

如果你想構建一個 Node 應用,首先要做的事情就是創建一個服務器。有一個最簡單的方法,就是使用 Express,它是一個精簡的 Node 應用程序框架。在開始之前,你應該優先考慮最新的版本。當你讀到這里的時候,本書使用的版本應該已經不是最新版了。

$ npm info express

3.0.0rc5

Now you can add it to your `package.json` file:
現在你可以把它加入到你的 `package.json` 文件中:
Example 5-1. `package.json`
示例 5-1. `package.json`
```js
{
 "name": "simple-express-static-server",
 "version": "0.1.0",
 "author": "Sandro Padin",
 "description": "A very simple static file server. For development use only.",
 "keywords": ["http", "web server", "static server"],
 "main": "./server.js",
 "scripts": {
 "start": "node ./server.js"
 },
 "repository": {
 "type": "git",
 "url": "https://github.com/spadin/simple-express-static-server.git"
 },
 "dependencies": {
 "express": "3.0.x"
 },
 "engines": {
 "node": ">=0.6"
 }
}

Notice that the express version is specified as "3.0.x". The x acts like a wildcard. It will install the latest 3.0 version, regardless of the patch number. It's another way of saying, "give me bug fixes, but no API changes". Node modules use Semantic Versioning. Read it as Major.Minor.Patch. Working backwards, bug fixes increment the patch version, non-breaking API changes increment the minor version, and backward breaking changes increment the major version. A zero for the major version indicates initial development. The public API should not be considered stable, and there is no indication in the version string for backward-breaking changes.

請注意 Express 的版本被指定為 3.0.x 。這里的 x 的作用相當于通配符。它將會安裝最新的 3.0 版本,無需指定補丁版本號。換句話說就是,“給我最新的 bug 修復版,但 API 不要變”。Node 模塊使用 語義化版本管理方式。它的格式是 主版本號.次版本號.補丁版本號。我們從后向前看,bug 修復性的更新將會增加補丁版本號,非破壞性的 API 更新將會增加次版本號,而無法向后兼容的大更新將會增加主版本號。主版本號為零表示這是首個開發版本,模塊的公開 API 還不夠穩定,并且版本字符串也不會告訴你是否存在向后兼容的問題。

Now that your package and dependencies are declared, return to the console and run:

既然你的包和依賴關系都已經聲明好了,讓我們回到控制臺并且運行一下:

$ npm install
[email protected] node_modules/express
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] ([email protected])
└── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected])

When you run npm install, it will look at package.json and install all of the dependencies for you, including those that were declared by the express package.

當你運行 npm install 時,系統就會尋找 package.json 文件,然后為你安裝所有的依賴庫,其中也包括 Express 自己聲明的依賴庫。

希望本文能幫助到您!

點贊+轉發,讓更多的人也能看到這篇內容(收藏不點贊,都是耍流氓-_-)

關注 {我},享受文章首發體驗!

每周重點攻克一個前端技術難點。更多精彩前端內容私信 我 回復“教程”

原文鏈接:https://github.com/cssmagic/blog/issues/37

「譯」 npm 包管理器

 

分享到:
標簽:npm
用戶無頭像

網友整理

注冊時間:

網站:5 個   小程序:0 個  文章:12 篇

  • 51998

    網站

  • 12

    小程序

  • 1030137

    文章

  • 747

    會員

趕快注冊賬號,推廣您的網站吧!
最新入駐小程序

數獨大挑戰2018-06-03

數獨一種數學游戲,玩家需要根據9

答題星2018-06-03

您可以通過答題星輕松地創建試卷

全階人生考試2018-06-03

各種考試題,題庫,初中,高中,大學四六

運動步數有氧達人2018-06-03

記錄運動步數,積累氧氣值。還可偷

每日養生app2018-06-03

每日養生,天天健康

體育訓練成績評定2018-06-03

通用課目體育訓練成績評定