Docs HomeNode.js

Download and Install下载并安装

1

Install Node and npm安装Node和npm

Ensure you have Node.js v12 or later and npm (Node Package Manager) installed in your development environment.确保在开发环境中安装了Node.js v12或更高版本和npm(Node Package Manager)。

For information on how to install Node.js and npm, see downloading and installing Node.js and npm.有关如何安装Node.js和npm的信息,请参阅下载和安装Node.js和npm

2

Create a Project Directory创建项目目录

In your shell, run the following command to create a directory called node_quickstart for this project:在shell中,运行以下命令为该项目创建一个名为node_quickstart的目录:

mkdir node_quickstart

Run the following command to navigate into the project directory:运行以下命令导航到项目目录:

cd node_quickstart

Run the following command to initialize your Node.js project:运行以下命令来初始化Node.js项目:

npm init -y

When this command successfully completes, you should have a package.json file in your node_quickstart directory.当这个命令成功完成时,您应该在node_quickstart目录中有一个package.json文件。

3

Install the Node.js Driver安装Node.js驱动程序

Run the following command in your shell to install the driver in your project directory:在shell中运行以下命令,在项目目录中安装驱动程序:

npm install mongodb@5.7

This command performs the following actions:此命令执行以下操作:

  • Downloads the mongodb package and the dependencies it requires下载mongodb包及其所需的依赖项
  • Saves the package in the node_modules directory将包保存在node_modules目录中
  • Records the dependency information in the package.json file将依赖关系信息记录在package.json文件中

After you complete these steps, you should have Node.js and npm installed and a new project directory with the driver dependencies installed.完成这些步骤后,您应该安装Node.js和npm,并安装一个带有驱动程序依赖项的新项目目录。

Note

If you run into issues on this step, ask for help in the MongoDB Community Forums or submit feedback using the Share Feedback tab on the right or bottom right side of this page.如果在此步骤中遇到问题,请在MongoDB社区论坛中寻求帮助,或使用此页面右侧或右下角的“共享反馈”选项卡提交反馈。

Next: Create a MongoDB Deployment