Saturday, 7 July 2018

[Socket.io, Express, HELP] Socket not running properly when required in other js program.

This is literally my second day working with node.js so I'm going to need some help.As stated in the title, I have created a basic socket as shown here. https://ift.tt/2IZYiZT of this works when I do "node socket". I connect to https://ift.tt/2NzP3U3 and "TEST" appears in the node console. However, I have a second file: "app.js". Inside it (along with various other code that I did *NOT* write) I have added "require('./js/socket.js');" (correct file path and all). When I run app.js, "listening" appears in console, but when I connect to https://ift.tt/2NzP3U3, it doesn't show "hi" like it did before in the browser AND it doesn't say "TEST" in the console like it did before. What is wrong? Thanks.Edit: Even when I put the socket.js code INSIDE app.js, it doesn't work. (Of course I move the public directory as needed.)

Submitted July 07, 2018 at 07:49PM by R2bEEaton_

No comments:

Post a Comment