In Javascript, when i call this function from another js file i get undefined in my console output. Can I return the json object know as "obj" and not have it be undefined?
module.exports = {
getTechnicPackInfo: function(id){
var http = require("https");
var options = {
"method": "GET",
"hostname": "solder.io",
"path": "/api/aurora-crafters/modpacks/" + id,
"headers": {
"accept": "application/json",
"content-type": "application/Json",
"authorization": "Bearer 00000000000000000000000000000"
}
};
var req = http.request(options, function (res) {
var chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function () {
var body = Buffer.concat(chunks);
var obj = JSON.parse(body);
return obj;
});
});
req.end();
}
}