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)

Adding Layouts


We have an index file, which will probably have an about file as well. We don't want to have a menu in both views and then in every other view we create. So what we can do is we can surround our views in a layout, and then in that layout we can provide the code that we want to be on every page. 

So in the views folder we'll create a new document and call this layout.pug. Let's open that up, grab the code right from the Basics window, and paste that into the layout.pug file:

doctype html
html
head
  title my jade template
body
  h1 Hello World

Let's save that!

Note

As mentioned before in the Back to basics section, the indents need to be either spaces or tabs. If these aren't formatted correctly you will get errors. I'm going to use spaces.

Now in the index file, we need to specify that we want to use that layout. So what we'll do is at the top, we'll use extends layout and then use block content. We'll then use h3 Hello World and this has to be inside block content, so we'll put...