title: Express4.10 bodyParser req.body undefined
body: <p>I'm trying to build the login of a node application trying to access the route / login get: req.body undefined</p>
  
  <p>Error:</p>
  
  <pre><code>TypeError: Cannot read property 'usuario' of undefined
     at login (/home/makros/workspace/ntalk/controllers/home.js:8:24)
     at Layer.handle [as handle_request] (/home/makros/workspace/ntalk/node_modules/express/lib/router/layer.js:82:5)
     at next (/home/makros/workspace/ntalk/node_modules/express/lib/router/route.js:100:13)
     at Route.dispatch (/home/makros/workspace/ntalk/node_modules/express/lib/router/route.js:81:3)
     at Layer.handle [as handle_request] (/home/makros/workspace/ntalk/node_modules/express/lib/router/layer.js:82:5)
     at /home/makros/workspace/ntalk/node_modules/express/lib/router/index.js:235:24
     at Function.proto.process_params (/home/makros/workspace/ntalk/node_modules/express/lib/router/index.js:313:12)
     at /home/makros/workspace/ntalk/node_modules/express/lib/router/index.js:229:12
     at Function.match_layer (/home/makros/workspace/ntalk/node_modules/express/lib/router/index.js:296:3)
     at next (/home/makros/workspace/ntalk/node_modules/express/lib/router/index.js:190:10)
  </code></pre>
  
  <p>app.js</p>
  
  <pre><code>var express = require('express'),
  load = require('express-load'),
  cookieParser = require('cookie-parser'),
  session = require('express-session'),
  bodyParser = require('body-parser'),
  app = express();
  
  
  load('models')
      .then('controllers')
      .then('routes')
      .into(app);
  
  app.set('views', __dirname + '/views');
  app.set('view engine', 'ejs');
  
  app.use(cookieParser('secret'));
  app.use(session({
      secret: 'secret', 
      resave: true, 
      saveUninitialized: true
  }));
  
  app.use(bodyParser.urlencoded({ extended: false }));
  app.use(bodyParser.json());
  
  app.use(express.static(__dirname + '/public'));
  
  app.listen(3000,function(){
      console.log('Started!');
  });
  </code></pre>
  
  <p>package.json</p>
  
  <pre><code>{
    "name": "ntalk",
    "version": "1.0.0",
    "private": true,
    "scripts": {
    "start": "node ./bin/www"
    },
    "dependencies": {
    "body-parser": "^1.9.0",
    "cookie-parser": "^1.3.3",
    "ejs": "~0.8.5",
    "express": "&gt;= 0.0.0",
    "express-load": "^1.1.14",
    "express-session": "^1.8.2"
    }
  }
  </code></pre>
  
  <p>controllers/home.js</p>
  
  <pre><code>module.exports = function(app) {
      return {
          index: function(req, res) {
              res.render('home/index');
          },
          login: function(req, res){
              console.log(req.params);
              var email = req.body.usuario.email,
                  nome = req.body.usuario.nome;
              if(email &amp;&amp; nome) {
                  var usuario = req.body.usuario;
                  usuario['contatos'] = [];
                  req.session.usuario = usuario;
                  res.redirect('/contatos');
              } else {
                  res.redirect('/');
              }
          },
          logout: function(req, res){
              req.session.destroy();
              res.redirect('/');
          }
      };
  };
  </code></pre>
  
  <p>routes/home.js</p>
  
  <pre><code>module.exports = function(app) {
      var home = app.controllers.home;    
      app.get('/', home.index);
      app.get ('/entrar', home.login);
      app.get('/sair', home.logout);
  };
  </code></pre>
  
  <p>views/home/index.ejs</p>
  
  <pre><code>&lt;% include ../header %&gt;
          &lt;header&gt;
              &lt;h1&gt;Ntalk&lt;/h1&gt;
              &lt;h4&gt;Bem-vindo!&lt;/h4&gt;
          &lt;/header&gt;
          &lt;section&gt;
              &lt;form action="/entrar" method="post"&gt;
                  &lt;input type="text" name="usuario[nome]" placeholder="Seu nome"&gt;
                  &lt;br&gt;
                  &lt;input type="text" name="usuario[email]" placeholder="Seu e-mail"&gt;
                  &lt;br&gt;
                  &lt;button type="submit"&gt;Entrar&lt;/button&gt;
              &lt;/form&gt;
          &lt;/section&gt;
  &lt;% include ../footer %&gt;
  </code></pre>
  
  <p>Please help me!</p>