Node.js Get-TypeError:路径必须是绝对路径,或者在Expressjs中指定res.sendFile的根
这是我的密码:-Node.js Get-TypeError:路径必须是绝对路径,或者在Expressjs中指定res.sendFile的根,node.js,express,Node.js,Express,这是我的密码:- app.get('/',function(req,res){ res.sendFile('index.html'); }); 获取以下错误:- TypeError: path must be absolute or specify root to res.sendFile at ServerResponse.sendFile 您需要指定“index.html”的完整路径,或者执行以下操作 变量选项={'root':}; res.sendFile('index.html'
app.get('/',function(req,res){
res.sendFile('index.html');
});
获取以下错误:-
TypeError: path must be absolute or specify root to res.sendFile
at ServerResponse.sendFile
您需要指定“index.html”的完整路径,或者执行以下操作
变量选项={'root':};
res.sendFile('index.html',选项);
如果要使用相对路径,则需要提供绝对路径或指定发送文件的根
绝对路径
提供一个绝对路径,如E:\\myProj\\static\\index.html
或提供类似根的
res.sendFile('index.html',{ root: "E:\\myProj\\static"});
错误消息说明了一切。提供绝对路径!或者指定res.sendfile的根,我在其中添加了指定根??如果您觉得这个答案对您有帮助,您可以。