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)

Truncating text and categories view


In this section, we will be doing a couple of different things. One we want to make it so that the images show if there is an image on the post:

We also want to truncate the text because right now if we have a long post it's will show the whole body and we don't want that we want to just show a portion of it and then click Read More, that'll go to a single post page. We also want to make it so that when we click on Category it'll show all the posts in that category.

So what I'm will do first is I'm will get rid of all these posts and we will start fresh. So I'm in the Mongo shell and I'm will say db.posts.remove and then we're just will pass in some empty curly braces, so that's will remove everything:

So if we reload we have nothing here, so let's go ahead and since we not we don't have our messages set up so we can do that:

After we add a category we want to have a message, let's see, which it should be doing because we have this:

req.flash('success', 'Category...