I have read the following stack overflow post and this one, but i still can't find the solution to my problem.
I have function defined in a utility.js file as follows:
let geocodeOptions = {
provider: 'google',
httpAdapter: 'https',
apiKey: 'GMAPKEY_HERE',
formatter: null
};
async function postInformation(message, bot) {
try {
let messageContent = message.content;
let EncId = await getDetails(messageContent), msg
const NodeGeocoder = require('node-geocoder');
geocoder = NodeGeocoder(geocodeOptions);
geocoder.reverse({ lat: EncId[0], lon: EncId[1] }).then(res => {
msg = "*" + res[0]['city'] + "*";
})
let post;
let delayValue = await Bluebird.delay(2000)
if (delayValue) {
post = getMsg1() + '\n' + getMsg2() + '\n' + EncId;
return await post
}
} catch (error) {
console.log(error)
}
}
And in the main file, I am calling it as follows:
const util = require('./utility')
util.postInformation(message, client).then(value => {
console.log("value from main file")
console.log(value) // Always prints undefined
})
I also tried following:
let value = await util.postInformation(message, client);
console.log("value from main file")
console.log(value) // Always prints undefined
Instead of redirecting to other posts, pls provide a solution to this problem, where is the mistake i am making here.