I need to fill my config object
var config = {
one: 1,
two: 2,
three: /* make an api request here */,
};
with a value of a API-request (http). The API returns a Json string like:
{ configValue: 3 }
How to write a function which fills in the configValue
from the API request?
I tried that:
const request = require('request');
var config = {
one: 1,
two: 2,
three: function() {
request.get('http://api-url',(err, res, body) => {
return JSON.parse(res.body).configValue;
};
}(),
};
console.log(config);
but the result is undefined
:
{ one: 1, two: 2, three: undefined }