Refactoring the server.js file to create POST todos route

To get started, inside of the server folder, we're going to make a new folder called db, and inside of the db folder we'll make a file where all of this Mongoose configuration will happen. I'm going to call that file mongoose.js, and all we need to do is take our Mongoose configuration code right here:

var mongoose = require('mongoose');
mongoose.Promise = global.Promise;
mongoose.connect('mongodb://localhost:27017/TodoApp');

Cut it out, and to move it over into mongoose.js. Now, we need to export something. What we're going to export is the mongoose variable. So essentially, when someone requires the mongoose.js file, they're going to have Mongoose configured and they're going to ...

Get Advanced Node.js Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.