Download and Install下载并安装
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。
Create a Project Directory创建项目目录
In your shell, run the following command to create a directory called 在shell中,运行以下命令为该项目创建一个名为node_quickstart
for this project: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
文件。
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 requiresmongodb
包及其所需的依赖项Saves the package in the将包保存在node_modules
directorynode_modules
目录中Records the dependency information in the将依赖关系信息记录在package.json
filepackage.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,并安装一个带有驱动程序依赖项的新项目目录。
If you run into issues on this step, ask for help in the MongoDB Community Forums如果在此步骤中遇到问题,请在MongoDB社区论坛中寻求帮助,或使用此页面右侧或右下角的“共享反馈”选项卡提交反馈。 or submit feedback using the Share Feedback tab on the right or bottom right side of this page.