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 每当我启动节点服务器并键入localhost:3000时,它都会给我一个错误:TypeError:fd必须是一个文件描述符_Node.js - Fatal编程技术网

Node.js 每当我启动节点服务器并键入localhost:3000时,它都会给我一个错误:TypeError:fd必须是一个文件描述符

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

我是一个新的初学者。我正在使用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.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