我正在使用knexjs来查询我的数据库。问题是,我想从DB中获取一些数据并将其导出,以便可以在其他文件中使用。下面是我的代码:
async function ebay() {
return new Promise(function(resolve, reject) {
db.select("*")
.from("ebay_site_credentials")
.then(data => {
var z = {
name: data[0].name,
pass: data[0].pass
};
resolve(z);
})
.catch(err => {
console.log(err);
});
});
}
async function app() {
var a = await ebay();
return a;
}
var a = app();
console.log(a);
我想在module.exports = {}中导出clientID、secretID和base64
但我得到的不是未定义就是Promise:{}
有什么想法吗?
谢谢!
发布于 2018-07-20 05:58:03
你可能会得到:
Promise { <pending> }
你可以这样做:
async function app(cb) {
let a = await ebay();
cb(a);
}
app(a => console.log(a)); //you can export out the a inside the callback
https://stackoverflow.com/questions/51430603
复制相似问题