简体   繁体   English

socket.io的节点服务器找不到本地主机

[英]node server for socket.io does not find localhost

I have following code in my server.js file 我的server.js文件中有以下代码

var mongo  = require('mongodb').MongoClient,
    client = require('socket.io').listen(8080).sockets;

When I execute node server.js then it does not show anything on terminal. 当我执行node server.js它不会在终端上显示任何内容。 When I type http://localhost:8080 in browser then in browser console I get Failed to load resource: the server responded with a status of 404 (Not Found) 当我在浏览器中键入http://localhost:8080在浏览器控制台中我Failed to load resource: the server responded with a status of 404 (Not Found)

Why and how can I fix this problem? 为什么以及如何解决此问题?

The service is running on port 8080, but there is no resource for the service to return/load hence the 404. I replicated your error just to see if there was something I was missing. 该服务正在端口8080上运行,但是没有资源可供该服务返回/加载404。因此,我复制了您的错误只是为了查看是否缺少某些内容。 If there was nothing running on port 8080 you would get something like Webpage unavailable . 如果8080端口上没有任何运行,您将得到类似Webpage unavailable Try looking through the docs and giving the server something to return. 尝试浏览文档并为服务器提供一些回报。 You stated yourself that the entire code works, so go from there. 您说自己整个代码都可以工作,所以从那里开始。 Those two lines alone are not going to serve anything on their own. 仅这两条线就不能自己提供任何服务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM