title: How to fix "TypeError: Cannot read property 'name' of undefined" NodeJs
body: <p>When i try to request form information to set var there is a TypeError</p>
  
  <p>NodeJS server on VS Code</p>
  
  <p>This is my app.js code (not full)</p>
  
  <pre><code>var express = require('express');
  var path = require('path');
  var cookieParser = require('cookie-parser');
  var exphbs = require('express-handlebars');
  var expressValidator = require('express-validator');
  var bodyParser = require('body-parser');
  var flash = require('connect-flash');
  var session = require('express-session');
  var passport = require('passport');
  var LocalStrategy = require('passport-local'),Strategy;
  var mongo = require('mongodb');
  var mongoose = require('mongoose');
  mongoose.connect('mongodb://localhost/loginapp', { useNewUrlParser: true });
  var db = mongoose.connection;
  
  var routes = require('./routes/index');
  var users = require('./routes/users');
  
  // APP INIT
  var app = express();
  
  // VIEW ENGINE
  app.set('views', path.join(__dirname,'views'));
  app.engine('handlebars', exphbs({ defaultLayout:'layout' }));
  app.set('view engine','handlebars');
  
  // BODYPARSER
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({ extended:false }));
  app.use(cookieParser());
  
  app.use('/', routes);
  app.use('/users', users);
  </code></pre>
  
  <p>users.js file</p>
  
  <pre><code>var express = require('express');
  var router = express.Router();
  
  // REGISTER
  router.get('/register', (req, res) =&gt; {
      res.render('register');
  });
  
  // LOGIN
  router.get('/login', (req, res) =&gt; {
      res.render('login');
  });
  
  // REGISTER
  router.post('/register', (req, res) =&gt; {
      var name = req.body.name;
      console.log(name);
  });
  
  module.exports = router;
  </code></pre>
  
  <p>Register file (.handlebars html)</p>
  
  <pre><code>&lt;h2 class="page-header"&gt;Register&lt;/h2&gt;
  &lt;form method="post" action="/users/register"&gt;
      &lt;div class="form-group"&gt;
          &lt;label&gt;Name&lt;/label&gt;
          &lt;input type="text" class="form-control" placeholder="Name" name="name"&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          &lt;label&gt;Username&lt;/label&gt;
          &lt;input type="text" class="form-control" placeholder="Username" name="username"&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          &lt;label&gt;Email&lt;/label&gt;
          &lt;input type="email" class="form-control" placeholder="Email" name="email"&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          &lt;label&gt;Password&lt;/label&gt;
          &lt;input type="password" class="form-control" placeholder="Password" name="password"&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          &lt;label&gt;Confirm Password&lt;/label&gt;
          &lt;input type="password" class="form-control" placeholder="Password" name="password2"&gt;
      &lt;/div&gt;
      &lt;button type="submit" class="btn btn-default"&gt;Submit&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>And when i try to submit the error happen.</p>
  
  <p>TypeError: Cannot read property 'name' of undefined
      at router.post (C:\Users\Corentin\Documents\loginapp\routes\users.js:16:25)
      at Layer.handle [as handle_request] (C:\Users\Corentin\Documents\loginapp\node_modules\express\lib\router\layer.js:95:5)
      at next (C:\Users\Corentin\Documents\loginapp\node_modules\express\lib\router\route.js:137:13)
      at Route.dispatch (C:\Users\Corentin\Documents\loginapp\node_modules\express\lib\router\route.js:112:3)
      at Layer.handle [as handle_request] (C:\Users\Corentin\Documents\loginapp\node_modules\express\lib\router\layer.js:95:5)
      at C:\Users\Corentin\Documents\loginapp\node_modules\express\lib\router\index.js:281:22
      at Function.process_params (C:\Users\Corentin\Documents\loginapp\node_modules\express\lib\router\index.js:335:12)
      at next (C:\Users\Corentin\Documents\loginapp\node_modules\express\lib\router\index.js:275:10)
      at Function.handle (C:\Users\Corentin\Documents\loginapp\node_modules\express\lib\router\index.js:174:3)
      at router (C:\Users\Corentin\Documents\loginapp\node_modules\express\lib\router\index.js:47:12)
      at Layer.handle [as handle_request] (C:\Users\Corentin\Documents\loginapp\node_modules\express\lib\router\layer.js:95:5)
      at trim_prefix (C:\Users\Corentin\Documents\loginapp\node_modules\express\lib\router\index.js:317:13)
      at C:\Users\Corentin\Documents\loginapp\node_modules\express\lib\router\index.js:284:7
      at Function.process_params (C:\Users\Corentin\Documents\loginapp\node_modules\express\lib\router\index.js:335:12)
      at next (C:\Users\Corentin\Documents\loginapp\node_modules\express\lib\router\index.js:275:10)
      at C:\Users\Corentin\Documents\loginapp\node_modules\express\lib\router\index.js:635:15</p>
  
  <p>Thanks a lot for peoples helping me, i spent to much hours with this problem</p>