Node.js - Get input values?

2

There I go again. I have a function where you make a record in the MySQL database it is working. But when trying to get data from an input I get the following error:

  

TypeError: Can not read property 'user' of undefined

Node:

exports.AddUser = function(request, reponse){
    console.log('Email: ', reponse.body.user.email);
    Model.addUser({email_usuario: Math.random() , senha_usuario:'sds' }, function(user){
        reponse.render('user/add', {
            title: 'cadastro'
        });
    }); 
};

Jade:

extends ../layout
block content
form(action="../user/add", method="post")
    label Email
    input(type="text" name="user[email]")
    label senha
    input(type="password" name="user[senha]")
    button(type="submit") Cadastrar
br

I already tried with reponse.body.email , input(type="text" name="senha") and it did not work, what's wrong here?

    
asked by anonymous 11.08.2015 / 21:40

1 answer

2
var express = require("express"),
    http = require("http"),
    path = require("path"),
    bodyParser = require('body-parser');

app = express();

app.set('port', 3000);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
    extended: true
}));

app.use(express.static(path.join(__dirname, 'static')));


require('./router')(app);

http.createServer(app).listen(app.get('port'), function(){
   console.log('Running');
});

I just added the 'body-parser' module and added this excerpt

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
    extended: true
}));


   console.log('Email: ', request.body.nome);
    
12.08.2015 / 05:01