0

I'm just installed request package.. so I want to get json data of an especific document through get request:

var Request = require("request");
var user_data = '';
Request.get("http://localhost:4000/users/"+some_id+"/find", (error, response, body) => {
    if(error) {
        return console.dir(error);
    }
    user_data = JSON.parse(body);
});

... do_something_with_data ...

But user_data only lives at that scope, how can I do that?

maudev
  • 974
  • 1
  • 14
  • 32
  • 2
    That's a "callback". All actions on returned data happen ***within*** the callback. Since I've seen promise based code from your account before, perhaps you should know that [`request-promise`](https://github.com/request/request-promise) has existed now for a very long time – Neil Lunn Nov 26 '18 at 03:33
  • Thats looks good I will try thanks again bro ! – maudev Nov 26 '18 at 03:40

0 Answers0