A
A
Abc Edc2015-01-27 11:48:37
Node.js
Abc Edc, 2015-01-27 11:48:37

Why does not find query parameters in this situation req,res in NodeJs?

routes

module.exports = function(app) {
app.get('/users', require('../controllers/model').CRUD.findAll);
};

and controller
module.exports.CRUD = {
  findById: function(req,res) {

/*К ПРИМЕРУ*/
res.json('response':req.body.response);

},
  findAll: function(req,res) {}
}

will give an error
TypeError: Cannot read property response; of undefined

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kazmiruk, 2015-01-27
@gleber1

What do you want to do with this line res.json('response':req.body.response);?
The error is quite fair: req.body is undefined by default and can be filled with body-parser ( expressjs.com/4x/api.html#req.body ). But even after filling it should not contain the response (if you do not stuff it there yourself), the response should be contained in the response variable (in your case res) passed to the handler. Plus, you have invalid json passed to res.json, you need res.json({key: value}). And the last thing - your code is not clear what it is doing. You are trying to display response in response. This is at least illogical action)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question