Creating the controllers folder

Instead of using the routes folder to create the route and functions of the comments file, we will use another format and create the controllers folder, where we can separate the route and the controller function, thus having a better modularization:

  1. Create a folder called controllers.
  2. Create a file called comments.js and add the following code:
          // get gravatar icon from email      var gravatar = require('gravatar');      // get Comments model      var Comments = require('../models/comments');           // List Comments      exports.list = function(req, res) {      // List all comments and sort by Date      Comments.find().sort('-created').populate('user', 'local.email').exec(function(error, comments) {      ...

Get Node.js 6.x Blueprints now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.