這個翻譯StrongLoop / IBM提供.

相對於英文版說明文件,本文件可能已不合時宜。如需最新的更新,請參閱英文版說明文件

安裝

假設您已安裝 Node.js,請建立目錄來保留您的應用程式,並使它成為您的工作目錄。

$ mkdir myapp
$ cd myapp

Use the npm init command to create a package.json file for your application. 使用 npm init 指令,為您的應用程式建立 package.json 檔。如需 package.json 如何運作的相關資訊,請參閱 Specifics of npm’s package.json handling

$ npm init

This command prompts you for a number of things, such as the name and version of your application. For now, you can simply hit RETURN to accept the defaults for most of them, with the following exception:

entry point: (index.js)

輸入 app.js,或您所要的主要檔名稱。如果您希望其名稱是 index.js,請按 RETURN 鍵,接受建議的預設檔名。 If you want it to be index.js, hit RETURN to accept the suggested default file name.

現在,將 Express 安裝在 myapp 目錄中,並儲存在相依關係清單中。例如: For example:

$ npm install express

如果只想暫時安裝 Express,而不新增至相依關係清單,請省略 --save 選項:

$ npm install express --no-save

安裝 Node 模組時,如果指定了 --save 選項,則會將這些模組新增至 package.json 檔中的 dependencies 清單。之後,當您在 app 目錄中執行 npm install 時,就會自動安裝相依關係清單中的模組。 Then, afterwards, running npm install in the app directory will automatically install modules in the dependencies list.

Next: Hello World

Edit this page