I have been working on a project where I am trying to return a value to app.js without having the promise processed. However, when I run the code, it returns undefined. Any suggestions on how to improve this?
export.js `
const admin = require('firebase-admin')
const db = admin.firestore();
const ref = db.collection('Things')
async function retrieveName(ting) {
return await ref.get().then(doc => {
doc.forEach(documentSnapshot => {
var data = documentSnapshot.data()
if (ting == data.name || ting == data.id) {
return data.name
}
})
})
};
module.exports.getName = function(ting) {
retrieveName(ting).then(value =>{
console.log(value)
return value;
})
};
app.js
const exp = require('./export.js')
var name = await exp.getName('foo')
console.log(name)