In this section, you're going to create your HTTP POST
route for adding new Todos. Before we dive into that, we're first going to refactor everything we have in server.js
. We have database configuration stuff which should live somewhere else and we have our models, which should also live in separate files. The only thing we want in server.js
is our Express route handlers.
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...