0

how can i add the body from the http get to a string (var GetText)?

var GetText ;
require('https').get('https://www.random.org/integers/?num=1&min=1&max=10&col=1&base=10&format=plain&rnd=new', (res) => {
res.setEncoding('utf8');
res.on('data', function (body) {
    console.log(body);
});
});
console.log(GetText);
  • Possible duplicate of https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call – vsemozhebuty Feb 07 '19 at 13:02

1 Answers1

0

You need a buffer variable to add upon inside res.on('data') then set the getString variable on the res.on('end') event. Here is a nice article if you want to read more on the issue.

https://nodejs.org/en/docs/guides/anatomy-of-an-http-transaction/

GisliBG
  • 21
  • 1
  • 2