【发布时间】:2017-09-16 16:41:41
【问题描述】:
我不断得到:
express deprecated res.sendfile: Use res.sendFile instead
这是我的代码:
app.get('/*', function (req, res) {
var myUrl = req.url.split('/')[1];
myownfunction(myUrl, function (err, rows) {
if (rows.length != 0) {
res.sendfile('views/article.html');
}
else
{
res.sendfile('views/404.html');
}
});
});
我将sendfile 更改为大写sendFile,但它中断了。
我该怎么办?
更新
当我运行我的代码时:
app.get('/upload', function(req, res){
res.sendFile('views/upload_file.html');
});
我收到此错误: TypeError: path must be absolute or specified root to res.sendFile
【问题讨论】:
-
“它坏了”,它是怎么坏的?你遇到了什么错误?
-
@BenFortune 我用我得到的错误更新了问题:TypeError: path must be absolute or specified root to res.sendFile
-
你试过
res.sendFile(path.join(__dirname,"views/upload_file.html"))吗(你可能需要导入nodeJs的路径模块)
标签: javascript node.js express filepath sendfile