Listen to res.sendFile errors in Express
Try this one, refer to the document res.sendFile
var options = {
root: __dirname + '/public/',
dotfiles: 'deny'
};
var fileName = path.resolve(folder, runId, 'temp.html');
res.sendFile(fileName, options, function (err) {
if (err) {
console.log(err);
res.status(err.status).end();
}
else {
console.log('Sent:', fileName);
}
});
Please have a detailed look at the documentation:
http://expressjs.com/en/4x/api.html#res.sendFile
According to the documentation, your code should look like this:
router.post('/foo', function(req,res,next){
var file = path.resolve(folder, runId, 'temp.html');
res.sendFile(file, options, function(err) {
if(err) {
res.status(err.status).end()
}
});
});
Hope this helps