I have two JS files running in a Node.js application.
In latlng.js I have this code:
async function getPlaceDetails(input) {
var locationUrl = 'https://www.google.com';
request(locationUrl, (error, response, body) => {
if (!error && response.statusCode == 200) {
let location_json = JSON.parse(body);
let placeDetails = {
lat: location_json.candidates[0].geometry.location.lat,
lng: location_json.candidates[0].geometry.location.lng,
name: location_json.candidates[0].name,
}
return placeDetails;
}
else {
console.log("Error "+response.statusCode);
}
});
}
module.exports.getPlaceDetails = getPlaceDetails;
I'm exporting the function getPlaceDetails() from latlng.js so I can use it in app.js, see here:
var place = require('./latlng');
async function firstFunction(input){
let data = await place.getPlaceDetails(input);
return data;
};
async function secondFunction(input){
let data = await firstFunction(input);
// now wait for firstFunction to finish...
console.log(data);
};
secondFunction('museum of modern art');
This returns undefined for me. I've been searching for hours today to get something other then undefined or Promise { undefined } but without success...