You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the Socket.IO documentation, consider removing references to createServer() and adding the use of app.listen() for server setup. This adjustment would streamline the documentation and make it more accessible, particularly for users who are new to Socket.IO and Express
Before
importexpressfrom'express';import{createServer}from'node:http';constapp=express();constserver=createServer(app);app.get('/',(req,res)=>{res.send('<h1>Hello world</h1>');});server.listen(3000,()=>{console.log('server running at http://localhost:3000');});
After
importexpressfrom'express';constapp=express();app.get('/',(req,res)=>{res.send('<h1>Hello world</h1>');});app.listen(3000,()=>{console.log('server running at http://localhost:3000');});
The text was updated successfully, but these errors were encountered:
priyankarpal
changed the title
Clarify in Socket.IO Docs that app.listen() Can Be Used Directly for Server Setup
Simplify Socket.Io Docs by Removing createServerApr 22, 2024
Hi! I'm not sure that this is a good idea, as the current way indicates that the Node.js HTTP server can be shared between Socket.IO and Express:
Current version (explicit):
importexpressfrom'express';import{createServer}from'node:http';import{io}from'socket.io';constapp=express();consthttpServer=createServer(app);app.get('/',(req,res)=>{res.send('<h1>Hello world</h1>');});httpServer.listen(3000,()=>{console.log('server running at http://localhost:3000');});constio=newServer(httpServer);
Suggested version (implicit):
importexpressfrom'express';import{io}from'socket.io';constapp=express();app.get('/',(req,res)=>{res.send('<h1>Hello world</h1>');});consthttpServer=app.listen(3000,()=>{console.log('server running at http://localhost:3000');});constio=newServer(httpServer);
There is also the risk that people mix the two:
importexpressfrom'express';import{createServer}from'node:http';import{io}from'socket.io';constapp=express();consthttpServer=createServer(app);app.get('/',(req,res)=>{res.send('<h1>Hello world</h1>');});aop.listen(3000,()=>{console.log('server running at http://localhost:3000');});constio=newServer(httpServer);
Which does not work because app.listen() creates another HTTP server.
In the Socket.IO documentation, consider removing references to
createServer()
and adding the use ofapp.listen()
for server setup. This adjustment would streamline the documentation and make it more accessible, particularly for users who are new to Socket.IO and ExpressBefore
After
The text was updated successfully, but these errors were encountered: