So I want to fetch data from my firebase realtime database in a firebase cloud function.
My Database structure:
My code:
let usernameFetched: string
const snapshot = await admin.database().ref(`/Agent/${userUID}/username`).once("value")
usernameFetched = snapshot.val().username
console.log(`${usernameFetched}`)
return res.status(200).send({
method: 'sendMessage',
chat_id,
text: `Your username is ${usernameFetched})
//This returns a message to user via a telegram bot.
}
I'm using typescript in VSCODE by the way.
The output is always UNDEFINED. Why? The path is correct. I tried all the ways from similar question but didn't helped me.
The function is ASYNC and I have to use the fetched value in other fucntions so I don't want to use return statement here. Any way?
