我有一个快速应用程序,其中有一个函数,我想在其中返回一个承诺并从端点返回该承诺。
这是我返回承诺的函数。
我的快速端点:
app.get('/logs', (req, res) =>{
const logs = socketNotification.fetchFiles();
});
然后我有我的功能,在那里我返回一个承诺。
const fetchFiles = () => {
return logs.then( file => {
const lines = file.lines;
lines.splice(-1);
const JSONlogs = lines.map(line => {
return({
log: JSON.parse(line)
});
});
})
}
module.exports = {
fetchFiles
}
现在我只返回JSONlogs存储在函数内的对象。有没有办法从函数中提取对象。我试过async/await,但我不确定关键字的位置。
子衿沉夜
炎炎设计
相关分类