Answer the question
In order to leave comments, you need to log in
How to wait for http response to finish loading in Node.js?
I'm making a site that has oAuth authorization/registration. Stuck on the problem of authorization through Google. I absolutely do not want to use googleapis modules for Node.js, because for each provider I write the authorization and registration algorithm itself.
The problem is that when I request an access_token , google displays the answer in parts, 3 parts in total, which I don't know how to put together.
I use to get a response:
res.on('data', function(chunk) {
gp_res = JSON.parse(chunk);
});
Answer the question
In order to leave comments, you need to log in
https://nodejs.org/api/http.html#http_class_http_c...
Read the documentation and guides. Fortunately, according to the standard API functions, you can find them through the same Google.
As for your example, write data somewhere within the scope of your closure.
var _json='';
socket.on('data', function(chunk) {
_json+=chunk.toString();
});
socket.on('end', function() {
var result=JSON.parse(_json);
...
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question