Created
August 27, 2021 18:29
-
-
Save SwapnilSoni1999/d3e2d33fc7a4a88acb7b9e2fadbd9cc7 to your computer and use it in GitHub Desktop.
Express and Socket.io without http module's createServer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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