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)

Single post and comments


In this section we will make it so that we can go to the Read More link, click on it, it'll show us the entire post and we'll also have comment functionality:

We want to do first is go in to route and then post.js and let's copy this:

router.get('/add', function(req, res, next) {
    var categories = db.get('categories');
    categories.find({},{},function(err, categories){
        res.render('addpost',{
            'title': 'Add Post',
            'categories': categories
        });
    });
});

And what we will do is say get/show/:id and then what we want to do is change this to posts, get('posts') and then change that to posts. And next we will pass functions to findById where we can actually get rid of these two and then we just want to pass in req.params.id:

router.get('/show/:id', function(req, res, next) {
  var posts = db.get('posts');
  posts.findById(req.params.id,function(err, post){
    res.render('show',{
      'post': post
    });
  });
});

Then we will...