Installing安装

Assuming you’ve already installed Node.js, create a directory to hold your application, and make that your working directory.假设你已经安装了Node.js,创建一个目录来保存你的应用程序,并将其作为你的工作目录。

$ mkdir myapp
$ cd myapp

Use the npm init command to create a package.json file for your application.使用npm init命令为您的应用程序创建一个package.json文件。 For more information on how package.json works, see Specifics of npm’s package.json handling.有关package.json如何工作的更多信息,请参阅npm的package.json处理细节

$ 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:现在,您只需点击RETURN即可接受其中大多数的默认值,但以下情况除外:

entry point: (index.js)

Enter app.js, or whatever you want the name of the main file to be. 输入app.js,或者任何你想要的主文件名。If you want it to be index.js, hit RETURN to accept the suggested default file name.如果你希望它是index.js,点击RETURN接受建议的默认文件名。

Now, install Express in the myapp directory and save it in the dependencies list. For example:现在,在myapp目录中安装Express并将其保存在依赖项列表中。例如:

$ npm install express

To install Express temporarily and not add it to the dependencies list:要临时安装Express而不将其添加到依赖项列表中,请执行以下操作:

$ npm install express --no-save

By default with version npm 5.0+, npm install adds the module to the dependencies list in the package.json file; with earlier versions of npm, you must specify the --save option explicitly. 默认情况下,在npm 5.0+版本中,npm install会将模块添加到package.json文件中的依赖列表中;对于早期版本的npm,必须显式指定--save选项。Then, afterwards, running npm install in the app directory will automatically install modules in the dependencies list.然后,在app目录中运行npm install会自动在依赖列表中安装模块。

Next: Hello World