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)

The Nodemailer contact form


We need to create our Contact form now!

  1. If I click on Contact now, we get an error because we didn't create that route or that view. Let's go to app.js, copy the app.get code, and edit it by typing in /contact and render the contact view:
app.get('/contact', function(req, res){
  res.render('contact');
});
  1. Let's save that and then inside the views folder, we'll create a new file and save it as contact.pug.
  1. Inside this file, we paste the following code. Copy the highlighted code lines as you would want the name and email of the customer visiting the contact form. First, we implement the name section:
      extends layout.pug

      block content
       .container
       form(method='post', action='contact/send')
       h1 Contact
.form-group
       label Name
       input.form-control(type='text')

You want these to be on the same level, and this one is going to be Email and we're going to give this one a type of email. The code should now look like so:

extends layout...