Installing安装
Assuming you’ve already installed Node.js, create a directory to hold your application, and make that your working directory.假设你已经安装了Node.js,创建一个目录来保存你的应用程序,并将其作为你的工作目录。
- Express 4.x
requires Node.js 0.10 or higher.需要Node.js 0.10或更高版本。 - Express 5.x
requires Node.js 18 or higher.需要Node.js 18或更高版本。
$ 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 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 install
会将模块添加到package.json
文件中的依赖列表中;对于早期版本的npm,必须显式指定--save
选项。Then, afterwards, running 然后,在app目录中运行npm install
in the app directory will automatically install modules in the dependencies list.npm install
会自动在依赖列表中安装模块。