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.myapp目录中安装Express,并将其保存在依赖项列表中。For example:例如:
$ npm install express --save
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 默认情况下,版本npm 5.0+ npm安装工具会将模块添加到dependencies list in the package.json file; with earlier versions of npm, you must specify the --save option explicitly.package.json文件中的dependencies列表中;对于早期版本的npm,必须显式指定--save选项。Then, afterwards, running 然后,在app目录中运行npm install in the app directory will automatically install modules in the dependencies list.npm install将自动安装依赖项列表中的模块。