Thank you for this boilerplate and the tutorial, it helped me understand how the back-end works and how it tied together.
I'm following the Clementine.js Beginner Tutorial, and I got an error in the Setting Up the Server-Side Controller section.
TypeError: db.collection is not a function
I found out that the tutorial expects to install MongoDB version 2, but I just installed the version 3.
"dependencies": {
"express": "^4.16.3",
"mongodb": "^3.1.0-beta4"
}
I found this StackOverflow answer and this changes between version 2 and version 3 to fix the error using the version 3 of MongoDB.
Here's my updated server.js
with MongoDB version 3 installed:
'use strict';
var express = require('express');
var routes = require('./app/routes/index.js');
var mongo = require('mongodb').MongoClient;
var app = express();
mongo.connect('mongodb://localhost:27017/clementinejs', function (err, client) {
if (err) {
throw new Error('Database failed to connect!');
} else {
console.log('MongoDB successfully connected on port 27017.');
}
var db = client.db('clementinejs');
app.use('/public', express.static(process.cwd() + '/public'));
app.use('/controllers', express.static(process.cwd() + '/app/controllers'));
routes(app, db);
app.listen(3000, function () {
console.log('Listening on port 3000...');
});
});
I hope it helps. Let me know if you want to upgrade to version 3 of MongoDB I would like to send a pull request for this.