安裝 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');
  }
});