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 ...

Get Learn Node.js by Building 6 Projects. now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.