【发布时间】:2019-06-06 22:36:17
【问题描述】:
我尝试从其他文件调用 firebase 作为函数以获得可读代码。但我的函数返回“未定义”
const db = require('firebasedbconfiguration');
exports.myFunction = async function(id){
await db.collection('stackovermachin')
.where('condition','==','workingInOtherFile')
.get()
.then(function(snapshot){
if(foo == 'blabla'){
let response = {
bar : bar,
foo : foo
}
console.log(response);
// { bar : bar,
// foo : foo}
return response;
}
.catch((error)=>{
let err = { message : error};
console.log(err)
// message : "error firebase message "
return err;
}
}
------------ (main file) ----------
const import = require('myfile');
let response = await import.myFunction("id99482")
console.log(response);
// undefined
哪里出错了?导出函数的最佳方式是什么?
【问题讨论】:
-
你需要从你的函数中返回
-
回报承诺
标签: node.js