安装 MongoDB
npm install --save mongodb
npm install --save mongoose //A simple wrapper for ease of development
在你的服务器文件中(通常名为 index.js 或 server.js)
const express = require('express');
const mongodb = require('mongodb');
const mongoose = require('mongoose');
const mongoConnectString = 'http://localhost/database name';
mongoose.connect(mongoConnectString, (err) => {
if (err) {
console.log('Could not connect to the database');
}
});