I want to save the HTML of an extern site in a var. I have the following code:
program.js
var request = require('request');
var htmlcode = "Code isn't defined right now!";
var siteUrl = "http://fluxnetz.de"
request({
uri: siteUrl,
}, function(error, response, body){
var htmlcode = body;
console.log(htmlcode);
}
);
//console.log(htmlcode);
When I want to output htmlcode outside of the request function it outputs "Code isn't defined right now!" But I set htmlcode to body before. And when I call console.log inside the function I get the right output but if I run it again outside it wont work.