Javascript TypeError:路径必须为绝对路径或指定res.sendFile的根

Javascript TypeError:路径必须为绝对路径或指定res.sendFile的根,javascript,node.js,mongodb,Javascript,Node.js,Mongodb,var express=require('express'); var-app=express(); var mongoose=require('mongoose'); var bodyParser=require('body-parser'); use(bodyParser.json()); 猫鼬。连接(“mongodb://localhost/test"); var todoschema=newmongoose.Schema({ 名称:{type:String,必需:true} }); va

var express=require('express');
var-app=express();
var mongoose=require('mongoose');
var bodyParser=require('body-parser');
use(bodyParser.json());
猫鼬。连接(“mongodb://localhost/test");
var todoschema=newmongoose.Schema({
名称:{type:String,必需:true}
});
var todomodel=mongoose.model('todolist',todoschema);
app.get('/',函数(req,res){
res.sendFile('C:/Users/Rohit/Desktop/newfolder/public/todo.html');
})
app.get('/todolist',函数(req,res){
todomodel.find(函数(错误、任务){
res.json(任务);
});
});
app.post('/todolist',函数(req,res){
插入(请求主体、函数(错误、任务){
res.json(任务);
});
});
app.delete('/todolist/:id',函数(req,res){
删除(req.params.id,函数(err,task){
res.json(任务);
});
});
app.get('/todolist/:id',函数(req,res){
todomodel.findById(req.params.id,函数(err,task){
res.json(任务);
});
});
app.put('/todolist/:id',函数(req,res){
todomodel.findAndModify({
查询:req.params.id,
更新:{$set:{name:req.body.name},
新:true},函数(err,task){
res.json(任务);
}
);
});
app.listen(3000);
log(“在端口3000上运行的服务器”)
更新

尝试使用

res.sendFile("C:\\Users\\Rohit\\Desktop\\New folder\\public\\todo.html");
@罗宾

查看express源代码,express/lib/utils.js

exports.isAbsolute = function(path){
  if ('/' == path[0]) return true;
  if (':' == path[1] && '\\' == path[2]) return true;
  if ('\\\\' == path.substring(0, 2)) return true; // Microsoft Azure absolute path
};
它只检查
\\
,我认为这是一个bug

更新

尝试使用

res.sendFile("C:\\Users\\Rohit\\Desktop\\New folder\\public\\todo.html");
@罗宾

查看express源代码,express/lib/utils.js

exports.isAbsolute = function(path){
  if ('/' == path[0]) return true;
  if (':' == path[1] && '\\' == path[2]) return true;
  if ('\\\\' == path.substring(0, 2)) return true; // Microsoft Azure absolute path
};

它只检查
\\
,我认为这是一个bug。

使用前斜杠<代码>C:/Users/…
我做了,还是相同的错误使用前斜杠<代码>C:/Users/…我做了,仍然是相同的错误它在工作,但是你为什么要双斜杠,基本上是单斜杠对吗?它在工作,但是你为什么要双斜杠,基本上是单斜杠对吗?