Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js Get-TypeError:路径必须是绝对路径,或者在Expressjs中指定res.sendFile的根_Node.js_Express - Fatal编程技术网

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的根,我在其中添加了指定根??如果您觉得这个答案对您有帮助,您可以。