Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/33.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 节点js应用程序在路由时被卡住_Node.js - Fatal编程技术网

Node.js 节点js应用程序在路由时被卡住

Node.js 节点js应用程序在路由时被卡住,node.js,Node.js,我有以下server.js文件 var express=require(“express”), http=require(“http”), 应用程序; app=express(); //设置用于detaulf路由的静态文件目录 应用程序使用(express.static(uu dirname+“/client”); http.createServer(app.listen)(3000); app.get(“/hello”,函数(req,res){ res.set(“你好,团队!”); });

我有以下server.js文件

var express=require(“express”),
http=require(“http”),
应用程序;
app=express();
//设置用于detaulf路由的静态文件目录
应用程序使用(express.static(uu dirname+“/client”);
http.createServer(app.listen)(3000);
app.get(“/hello”,函数(req,res){
res.set(“你好,团队!”);
});
在/client目录中,我有一个名为“index.html”的文件,所以当我转到localhost:3000/index.html时,会显示这个文件,这就是我所期望的

但是如果我转到localhost:3000/hello,页面将永远不会加载,并且会一直停留在“等待localhost”上,直到超时并显示“未收到数据”错误消息

如果我删除/client的代码行并只保留路由,那么它就可以正常工作。因此,在我看来,在我的/client目录下查找“/hello”似乎有点困难,但如果我理解正确,那么如果在该目录下找不到文件,服务器应该尝试使用其他路由


想法?

/hello
路线中有一个问题。您使用了
res.set(“你好,团队!”)用于为响应设置HTTP头,而不是用于发送响应

改为使用res.send('hello team!')向客户端发送响应


参考:

在“客户端”目录中是否有名为“hello”的文件?使用
res.send('hello team!')
是res.send还是res.set。我在documentationCorrect中找不到response.set(),有一个小的输入错误。谢谢