Skip to content

Latest commit

 

History

History
28 lines (22 loc) · 657 Bytes

section53.1.md

File metadata and controls

28 lines (22 loc) · 657 Bytes

Section 53.1: Mongoose connection

Make sure to have mongodb running first! mongod --dbpath data/

  • package.json
"dependencies": {
  "mongoose": "^4.5.5",
}
  • server.js (ECMA 6)
import mongoose from 'mongoose';

mongoose.connect('mongodb://localhost:27017/stackoverflow-example');
const db = mongoose.connection;
db.on('error', console.error.bind(console, 'DB connection error!'));
  • server.js (ECMA 5.1)
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost:27017/stackoverflow-example');
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'DB connection error!'));