Let us pass in a express server directly! #4135
-
hello everyone, I am Manav Ghai a full stack dev. I was making a discord clone for fun, and I used socket.io for live connection between two users on the platform. So, I use HTTP NodeJS built in library, but I don't like the syntax of it over express. I know the way of using express with socket.io is - const app = express(); app.set('view engine', 'ejs'); app.engine('ejs', ejsMate); app.use(express.urlencoded({ extended: true })); app.get('/', (req, res) => { app.listen(3000, () => { So, I think many other devs will be like this who don't like or know about HTTP NodeJS library. + express syntax is just the best and we should keep it that way and mix it up with any other library's or replace it with any other library's syntax. + I tried to find an other library and failed to find one just as good this one. So, think the following should happen -
Other thing which should happen -
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Come on. Respond. Plzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz, this is the best idea you will get in your life man. |
Beta Was this translation helpful? Give feedback.
-
Hi! You can totally reuse the httpServer that is returned by const express = require('express');
const ejsMate = require('ejs-mate');
const path = require('path');
const { Server } = require('socket.io');
const app = express();
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, 'views'));
app.engine('ejs', ejsMate);
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.get('/', (req, res) => {
res.send('lol');
})
const httpServer = app.listen(3000, () => {
console.log('serving on port 3000');
})
const io = new Server(httpServer);
io.on('connection', () => {
// ...
}); Regarding your other points:
If I understand correctly, you suggest that
Sure, who wouldn't? 😄 What do you suggest? |
Beta Was this translation helpful? Give feedback.
Hi! You can totally reuse the httpServer that is returned by
app.listen()
:Regarding your other points: