Node.js 每当我启动节点服务器并键入localhost:3000时,它都会给我一个错误:TypeError:fd必须是一个文件描述符
我是一个新的初学者。我正在使用VisualStudio代码工具,并尝试使用nodejs创建服务器 当用户向服务器发送请求时,我正在尝试加载index.html文件。我的js代码是:Node.js 每当我启动节点服务器并键入localhost:3000时,它都会给我一个错误:TypeError:fd必须是一个文件描述符,node.js,Node.js,我是一个新的初学者。我正在使用VisualStudio代码工具,并尝试使用nodejs创建服务器 当用户向服务器发送请求时,我正在尝试加载index.html文件。我的js代码是: var http=require('http'); var fs = require('fs'); http.createServer(function(req,res){ fs.read("./public/index.html","UTF-8", function(err,html){ res.w
var http=require('http');
var fs = require('fs');
http.createServer(function(req,res){
fs.read("./public/index.html","UTF-8", function(err,html){
res.writeHead(200,{'Content-type':'text/html'});
res.end(html);
} );
}).listen(3000);
TypeError: fd must be a file descriptor
at Object.fs.read (fs.js:686:11)
at Server.<anonymous> (E:\NodejsWork\server.js:7:7)
at Server.emit (events.js:180:13)
at parserOnIncoming (_http_server.js:642:12)
at HTTPParser.parserOnHeadersComplete (_http_common.js:117:17)
fs.read方法需要一个文件描述符作为参数,而不是文件路径。 您可能正在寻找的是fs.readFilepath[,options],callback