Skip to content
Sign upLog in
← Back to Community

Socket Problem Node

Profile icon
aboutabot

Hey, I just learned SocketIO and Express on a tutorial and I don't really know it that well, and I tried to send a message from one client to the server to the other client in a room. This only works if I run the repl from the server, and then reload both the https://server.aboutabot.repl.co page and the replit page I coded it on.
help?

Answered by Geocube101 [earned 5 cycles]
View Answer
Comments
hotnewtop
Profile icon
Geocube101

You may have to serve the html file containing your client side code

app.get('/', function(req, res) { res.sendFile(__dirname + "/public/index.html"); });
Profile icon
aboutabot

@Geocube101
I put it in now, but it no longer asks me for my room name or my name in the alert prompt

Profile icon
Geocube101

@aboutabot
there is an issue with the <script> tag as the html page cannot locate the js files.
Try using:

<script src="script.js"></script>

...to load your script.js file

Profile icon
aboutabot

@Geocube101
Ok, now I changed that, but the alert prompt still doesn't come.

Profile icon
Geocube101

@aboutabot
Ok, I had another look at my node.js repls. The script tag needs the full path to your file so try:

<script src="/public/script.js"></script>