I'm new to Java Script and here's what I'm stuck with. I've been trying to make a variable inside my function global so that I could use it in the other parts of the code. Nothing seems to be working so far. Below is my code:
var json2="-";
var request = require("request");
var smallpie1 =
"https://s3.amazonaws.com/vecareclientjson/user1/predictions.json";
var pre = {rejectUnauthorized: false,
url: smallpie1,
method: 'GET',
json: true
};
function test1(){
request(pre,function (error,response,body){
json2 = JSON.stringify(body);
console.log(json2);
});
};
console.log(json2);
Output:
-
[Done] exited with code=0 in 0.231 seconds
I was expecting the content in the json to overwrite the json2 object.
The goal is to make the json2 object inside the function test1() global.
test1()?