【发布时间】:2019-01-15 19:58:34
【问题描述】:
我在一个名为 resources.js 的文件中导出一个异步函数,如下所示:
//resourcess.js
module.exports = function(arg) {
let do_stuff = async (arg) => {
...
}
然后我需要这样的 routes.js 文件:
let importedFunc = require('./resourcess.js');
最后我像这样在 routes.js 中使用它:
app.post('/post', function(req, res) {
var a2 = req.body.a1;
importedFunc(a2).then(result => {
console.log(result);
res.render('index.ejs');
}).catch(err => {
console.log(err);
res.render('index.ejs');
})
});
这是我收到的错误消息:
TypeError: Cannot read property 'then' of undefined
我无法理解我做错了什么......
【问题讨论】:
标签: node.js module async-await export require