nodejs / node-v0.x-archive

Moved to https://github.com/nodejs/node

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

node request could not wait until response, even using callback

isian8814 opened this issue · comments

Here is the code I am testing, it does not return response every time. Like I run it 20 times, there is only one time I could get output of the body. Other times, I got nothing output, even not seeing any error messages.

I guess it is because the request runs too fast to get response back.

Could anyone help me with this?
Thanks.

I added output within the function(err,response,body), like below. But nothing got output.
get_from_google : function (callback) {
request('http://www.google.com', function(err, res, body) {
console.info('In the callback');
if (err)
return callback(err);
if (res.statusCode === 200) {
callback(new Error('Nothing got back'), body);
} else {
callback(new Error('Unexpected status code: ' + res.statusCode));
}
});
}

Here is console output:
Starting selenium standalone server...
[launcher] Running 1 instances of WebDriver
Selenium standalone server started at http://10.33.203.210:53537/wd/hub
Started
.

Ran 1 of 3 specs
1 spec, 0 failures
Finished in 0.019 seconds
Shutting down selenium standalone server.
[launcher] 0 instance(s) of WebDriver still running
[launcher] chrome #1 passed

Process finished with exit code 0

Hi @isian8814. Thanks for opening the issue. This doesn't appear to be an issue with Node.js core, so could you please open the issue at https://github.com/nodejs/help? Thanks!