Creating the application controller

Now the next step is to create the application controller's:

  1. Create a new file called locations.js inside app/controllers/ and add the following code:
          var express = require('express'), 
          router = express.Router(), 
          mongoose = require('mongoose'), 
          Location = mongoose.model('Location'); 
          module.exports = function (app) { 
          app.use('/', router); 
          }; 
          router.get('/locations', function (req, res, next) { 
          Location.find(function (err, item) { 
          if (err) return next(err); 
            res.render('locations', { 
              title: 'Locations', 
              location: item, 
              lat: -23.54312, 
              long: -46.642748 }); //res.json(item);      });      });      router.get('/locations/add', function (req, res, next) {      res.render('add-location', ...

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.