Aditya Verma
07/06/2023, 9:45 AMconst app = require('express')();
const http = require('http').Server(app);
const io = require('<http://socket.io|socket.io>')(http, {
cors: {
origin: '*',
}
});
const port = process.env.PORT || 3000;
io.on('connection', (socket) => {
console.log('user connected to socket')
socket.on('chat message', msg => {
io.emit('chat message', msg);
});
});
http.listen(port, () => {
console.log(`<http://Socket.IO|Socket.IO> server running at <http://localhost>:${port}/`);
});