June 2014
Intermediate to advanced
696 pages
38h 52m
English
Listing 27.6 implements the route handling code for the Page model. There is only one route, the getPage() route, which finds the page based on the name field and returns an error or the JSON string form of the object. The name of the page to find comes in as pageName in the GET query string.
Listing 27.6 pages_controller.js: Implementing the getPage route for the Express server
01 var mongoose = require('mongoose'),02 Page = mongoose.model('Page');03 exports.getPage = function(req, res) {04 Page.findOne({ name: req.query.pageName })05 .exec(function(err, page) {06 if (!page){07 res.json(404, {msg: 'Page Not Found.'});08 } else {09 res.json(page); ...
Read now
Unlock full access