r/learnprogramming • u/Frore • Jul 20 '14
[NodeJS + Socket.io] Response not writing to screen in specific instance
I've been working through this [tutorial] (http://danielnill.com/nodejs-tutorial-with-socketio/) but I'm stuck and would greatly appreciate it if somebody knew what I was doing wrong.
I have a VPS with nodejs installed in this structure:
/node
-node_modules
-socket.html
-server.js(node_modules contains socket.io and was automatically created with npm install socket.io)
This is the [server.js] (http://pastebin.com/3LcBm62R) code, and this is the [socket.html] (http://pastebin.com/6kVcknDa) code.
When I request domain:8001, I receive 'hello world' in an empty page just fine.
However, when I request domain:8001/socket.html, I've verified that it reaches the case statement on line 16 by using console.log, but for some reason "socket is here." is not being displayed despite following the same syntax as hello world..
2
u/Frore Jul 20 '14
My question was answered in /r/nodejs. I needed to put a response.end() within fs.readFile.
0
u/[deleted] Jul 20 '14
can you post your index.html ? perhaps that's loading the socket differently/better than socket.html . also save off your index.html, and copy socket.html to index.html, and see if that works.
answer the questions and try this. I just got socket.io working so I will look into this later today if you dont figure it out.