0
Follow
0
View

Node js with express and socket.io -can't fint socket.io.js

daishenmin 注册会员
2023-01-25 18:48

Well the problem was that I used:

app.listen(5001, () => {
console.log("Server started on Port 5001");
})

instead of:

server.listen(5001, () => {
console.log("Server started on Port 5001");
})
djzhao76 注册会员
2023-01-25 18:48

Szia, you will need to wait for the DOM to load.

window.addEventListener('load', function () {   

  // Your code goes here
  const socket = io();

  socket.on("connect", () => {
    // you can only emit once the connection is established.
    socket.emit('joinRoom', { username, room });
  });

})

About the Author

Question Info

Publish Time
2023-01-25 18:48
Update Time
2023-01-25 18:48

Related Question