I'm somewhat new to Nodejs. In the following code I'm getting data from an API.
request.post({ url:endpoint, form: requestParams }, function (err, response, body) {
if (err) {
console.log("Error = " + err);
}
else {
let parsedBody = JSON.parse(body);
if (parsedBody.error_description) {
console.log("Error = " + parsedBody.error_description);
}
else {
// testFunc(AccessToken);
test = "Success!";
testFunc(test);
}
}
});
function testFunc(success){
Token = success;
console.log(Token);
}
// this code gives the error "Token is not defined" \/
console.log(Token);
in the post request i make the variable "test". I want to be able to use this as a global variable so i can use it in a get request.
When i console.log() "Token" in the "testFunc" it will log it correctly.
But when i console.log() outside the function it gives the error Token is not defined.
How can i get the "Token" or the "test" variable to be global so i can use it in another get request?
Thanks in advance!