带有Socket.io 404错误的Node.js Express服务器 [英] Node.js Express Server with Socket.io 404 Error
问题描述
对我来说很清楚,我是一名低于平均水平的程序员,并且没有互联网上的express/socket.io服务器的实际示例.尝试加载页面时为什么会出现此错误?
It’s become clear to me that I am a below average programmer and there is no such thing as a working example of an express/socket.io server on the internet. Why am I getting this error when I try to load the page?
GET http://localhost:3700/socket.io/socket.io.js 404 (Not Found)
我在工作目录中执行了以下命令以安装express和socket.io
I executed the following command inside of my working directory to install express and socket.io
Npm install
我的package.json文件看起来像这样
My package.json file looks like this
{
"name": "RealTimeWebChat",
"version": "0.0.0",
"description": "Real time web chat",
"dependencies": {
"socket.io": "latest",
"express": "latest",
"jade": "latest"
},
"author": "developer"
}
这创建了一个"node_modules"目录,其中有一个"socket.io"目录.
This created a "node_modules" directory, inside of which is a "socket.io" directory.
那为什么我的应用程序找不到socket.io.js文件?
So why can’t my application find the socket.io.js file?
Other relevant information, I’m working off this tutorial. I’m following it word for word.
I have a .jade file that looks like this.
!!!
html
head
title= "Real time web chat"
script(src='/chat.js')
script(src='/socket.io/socket.io.js')
body
#content(style='width: 500px; height: 300px; margin: 0 0 20px 0; border: solid 1px #999; overflow-y: scroll;')
.controls
input.field(style='width:350px;')
input.send(type='button', value='send')
诚然,我不知道什么是玉,但我只是想尝试一个简单的例子并使其运行.我学得最好.最终项目定于周日!帮助我需要一台服务器!
Admittedly, I have no idea what jade is, but I'm just trying to get a simple example up and running. I learn best as I do. Final project is due on Sunday! Help I need a server!
推荐答案
我在GitHub的尝试一下:
git clone https://github.com/hectorcorrea/intro-to-nodejs.git
cd intro-to-nodejs
npm install
npm install socket.io
node socketioDemo
然后打开两个浏览器窗口并浏览到 http://localhost:3000
,您应该能够在两者之间交换消息.
Then open two browser windows and browse to http://localhost:3000
and you should be able to exchange messages between the two.
这篇关于带有Socket.io 404错误的Node.js Express服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!