O'Reilly logo

Node.js 6.x Blueprints by Fernando Monteiro

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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) {      ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required