Book Image

Learn Node.js by Building 6 Projects

By : Eduonix Learning Solutions
Book Image

Learn Node.js by Building 6 Projects

By: Eduonix Learning Solutions

Overview of this book

<p>With its event-driven architecture and efficient web services capabilities, more and more companies are building their entire infrastructure around Node.js. Node has become a de facto part of web development that any serious developer needs to master.</p> <p>This book includes six Node.js projects that gradually increase in complexity. You'll start by building a simple web server and create a basic website. You will then move to create the login system, blog system, chat system, and e-learning system.</p> <p>By creating and following the example projects in this book, you’ll improve your Node.js skills through practical working projects, and you'll learn how to use Node.js with many other useful technologies, such as ExpressJS, Kickstart, and Heroku.</p>
Table of Contents (12 chapters)

Fetching classes – part B


In this section, we're going to set up the Classes page:

The error page

Here's so the details page. OK, so what we need to do is we need to create a new routes file

Setting up new route file – classes.js

We're going to call this new routes file classes.js. Then what we'll do is copy everything from index.js and paste that in:

var express = require('express');
var router = express.Router();

var Class = require('../models/class');

/* Get home page */
router.get('/', function(req, res, next) {
   Class.getClasses(function(err, classes){
       res.render('index', { classes: classes });
   },3);
});

module.exports = router;

This is pretty much going to stay the same except we want to change the render to classes/index:

var express = require('express');
var router = express.Router();

var Class = require('../models/class');

// Classes Page 
router.get('/', function(req, res, next) {
   Class.getClasses(function(err, classes){
       res.render('classes/index', { classes...