response body(res.body) is always undefined.
See original GitHub issueversion: 1.8.3
platform: nodejs
I am trying to use super agent in my nodejs application and find an issue that ‘res.body’ in my response is always undefined. The content in response is in Json and I can see it in res.text. After some investigation I am able to spot the code which cases this issue:
// /lib/node/index
// line 883 to 886
parse(res, function(err, obj){ // Expects an argument
if (err && !self._aborted) self.callback(err);
res.body = obj;
}
// lib/node/parsers/text.js
module.exports = function(res, fn){
res.text = '';
res.setEncoding('utf8');
res.on('data', function(chunk){ res.text += chunk; });
res.on('end', fn); // No argument is given.
};
As the above indicates, parse function’s callback expects one argument but nothing is given when it is called.
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Express.js req.body undefined - Stack Overflow
I read that this problem is caused by the lack of app.use(express.bodyParser()); but as you can see I call it before the routes....
Read more >response body(res.body) is always undefined. #990 - GitHub
I am trying to use super agent in my nodejs application and find an issue that 'res.body' in my response is always undefined....
Read more >How to fix "req.body undefined" in Express.js
In this post we will learn how to fix the "req.body undefined" error in Express.js Framework.
Read more >req.body undefined in POST request - Google Groups
I seem to have a problem with req.body being "undefined" when using a. POST request. Im using expresso to do the POST: --...
Read more >5.x API - Express.js
A new body object containing the parsed data is populated on the request object after the middleware (i.e. req.body ), or an empty...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The text parser sets only
.text
.For custom parsers it’s sort-of broken. The end callback doesn’t wait for the parser to finish - #950, so you need
.buffer(true)
.thanks, @pornel