Answer the question
In order to leave comments, you need to log in
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);
};
module.exports.CRUD = {
findById: function(req,res) {
/*К ПРИМЕРУ*/
res.json('response':req.body.response);
},
findAll: function(req,res) {}
}
TypeError: Cannot read property response; of undefined
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question