'How to get a value out of a callback function in javascript [duplicate]

var request = require('request');
var d;
request('my.servers.ip?group=1', function (error, response, body) {
        let d = body
})
console.log(d)

This is my code currently, it says the variable d is undefined and I'm not sure why.

Anyone have ideas on why it might be?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source