Creating model files

Now let's create the application's template files. Since we are using the mongoose middleware used in chapter 1, Building a Twitter-Like Application Using the MVC Design Pattern in Node.js, we will keep the same type of configuration:

  1. Create a file called comments.js inside the models folder at server/models and add the following code:
     // load the things we need var mongoose = require('mongoose'); var Schema = mongoose.Schema; var commentSchema = mongoose.Schema({ created: { type: Date, default: Date.now }, title: { type: String, default: '', trim: true, required: 'Title cannot be blank' }, content: { type: String, default: '', trim: true }, user: { type: Schema.ObjectId, ref: 'User' } }); module.exports = mongoose.model('Comments', ...

Get Node.js 6.x Blueprints 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.