Skip to content

Instantly share code, notes, and snippets.

@SwapnilSoni1999
Created August 27, 2021 18:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SwapnilSoni1999/d3e2d33fc7a4a88acb7b9e2fadbd9cc7 to your computer and use it in GitHub Desktop.
Save SwapnilSoni1999/d3e2d33fc7a4a88acb7b9e2fadbd9cc7 to your computer and use it in GitHub Desktop.
Express and Socket.io without http module's createServer
const express = require('express')
const socket = require('socket.io')
const PORT = 5000
const app = express()
const server = app.listen(PORT, () => console.log(`Server started on port ${PORT}`))
const io = new socket.Server(server)
io.on("connection", function(socket) {
console.log("A new socket has joined: " + socket.id)
socket.on("hello", function(data) {
console.log(data);
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment