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

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.

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

1 Like

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