Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Copilot Lvl 2
Message 1 of 3

How do I connect my HTML document to my Socket.io Heroku server

Solved! Go to Solution.

I recently learned socket.io and I made a simple app with it, and then published it on a heroku app.

They say you should write this code in your html document for socket.io:

 
<script>
$(document).ready(function () {
const socket = io();

$('form').submit((e) => {
e.preventDefault();

socket.emit('chat message', $('#m').val());
$('#m').val('');
return false;
});

socket.on('chat message', (msg) => {
$('#messages').append(`<li>Message: ${msg}</li>`);
});
});
This is from socket.io's documentation page.
 
But I can't figure out how I connect to my heroku app were my socket.io's index.js lies so my html document can read the emitted events.
2 Replies
Solution
Copilot Lvl 2
Message 2 of 3

Re: How do I connect my HTML document to my Socket.io Heroku server

Nevermind, I solved it! Just put your heroku app url inside io([here]).

Community Manager
Message 3 of 3

Re: How do I connect my HTML document to my Socket.io Heroku server

Hey @SebastianElstadt, Thanks for coming back to share what worked for you!

Mark helpful posts with Accept as Solution to help other users locate important info. Don't forget to give Kudos for great content!