doc suggestion: do not use express app.listen() with socket.io
See original GitHub issueI ran into this in the process of adding socket.io to an existing express(4) app because i didn’t switch the code from app.listen()
to server.listen()
.
The symptom is refusal by the server to serve the client library or connect any sockets.
According to http://expressjs.com/4x/api.html#app.listen , “This method is identical to node’s http.Server.listen()” - but in reality it creates a new http server leaving the one with socket.io non-operational.
Hopefully this issue will help others to avoid the same trap.
Issue Analytics
- State:
- Created 8 years ago
- Reactions:7
- Comments:5 (1 by maintainers)
Top Results From Across the Web
How to use app.listen with Socket.io in Node? - Stack Overflow
If you want to run socket.io on the same port as webserver, you can try this: const app = express(); const server =...
Read more >Server Initialization | Socket.IO
Once you have installed the Socket.IO server library, you can now init the server. The complete list of options can be found below....
Read more >Everything you need to know about Socket.IO - Ably Realtime
A popular way to demonstrate the two-way communication Socket.IO provides is a basic chat app (we talk about some other use cases below)....
Read more >Migrating to Express 4
The http module is no longer needed, unless you need to directly work with it (socket.io/SPDY/HTTPS). The app can be started by using...
Read more >Node.js Socket.io Complete Tutorial - Codedamn
const express = require('express'); const app = express(); app.get('/', (req, res) => ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
+1
Did a bit more research and found a way (more details here) to stick with
app.listen()
:which seems to work the same as:
This is indeed a common trap… A note was added here: https://socket.io/docs/v3/server-initialization/#With-Express