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 register form and validation


Now that we have our views and layouts all set, we want to be able to register a user. So we have our form and if we open up routes/users, you can see we have a couple of requests but we have all get requests. We need a post request to user/register. So I'll copy the route.get method and I'll change get to post, and let's get rid of res.render:

router.get('/register', function(req, res, next) {
  res.render('register',{title: 'Register'});
});

router.get('/login', function(req, res, next) {
  res.render('login',{title: 'Login'});
});

router.post('/register', function(req, res, next){

});

Now it's really important to understand that when we submit a form and we can grab the data using req.body.email. We usually do that using body-parser, which we have installed and set up, but body-parser cannot handle file uploads and we have the profile image upload, that's where multer comes in. If we look at our app.js file, you can see we have this, and we'll set our...