1
这是我在express中遇到的问题。 在我的快递中间件的某处,我想检查文件的存在。如何将快捷参数传递给nodejs异步调用
//Setting up express middeleware...
app.use(f1);
app.use(f2);
...
function f1(req, res, next) {
...
//Here I want to check if 'somefile' exists...
fs.access('somefile', callback1, req, res, next);
}
//In the callback, I want to continue with the middleware...
function callback1(err, req, res, next) {
if (err) {
//Report error but continue to next middleware function - f2
return next();
}
//If no error, also continue to the next middleware function - f2
return next();
}
function f2(req, res, next) {
}
我如何通过REQ,资源,未来作为参数fs.access的回调? 上面的代码不起作用。我怀疑我需要使用闭包,但是如何?
查看问题的完全不同的方式是:如何将fs.access本身用作明确的中间件功能?
我认为这样会更好地描述你正在尝试做的事情,因为目前你正在尝试做什么并没有什么意义...... –