New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify Socket.Io Docs by Removing createServer
#5003
Labels
question
Further information is requested
Comments
priyankarpal
changed the title
Clarify in Socket.IO Docs that
Simplify Socket.Io Docs by Removing Apr 22, 2024
app.listen()
Can Be Used Directly for Server SetupcreateServer
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): import express from 'express';
import { createServer } from 'node:http';
import { io } from 'socket.io';
const app = express();
const httpServer = createServer(app);
app.get('/', (req, res) => {
res.send('<h1>Hello world</h1>');
});
httpServer.listen(3000, () => {
console.log('server running at http://localhost:3000');
});
const io = new Server(httpServer); Suggested version (implicit): import express from 'express';
import { io } from 'socket.io';
const app = express();
app.get('/', (req, res) => {
res.send('<h1>Hello world</h1>');
});
const httpServer = app.listen(3000, () => {
console.log('server running at http://localhost:3000');
});
const io = new Server(httpServer); There is also the risk that people mix the two: import express from 'express';
import { createServer } from 'node:http';
import { io } from 'socket.io';
const app = express();
const httpServer = createServer(app);
app.get('/', (req, res) => {
res.send('<h1>Hello world</h1>');
});
aop.listen(3000, () => {
console.log('server running at http://localhost:3000');
});
const io = new Server(httpServer); Which does not work because Does that make sense? |
darrachequesne
added
question
Further information is requested
and removed
to triage
Waiting to be triaged by a member of the team
labels
Apr 23, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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: