Node Websocket Server Base
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
'use strict'; | |
const express = require('express'); | |
const socketIO = require('socket.io'); | |
const PORT = process.env.PORT || 3000; | |
const INDEX = '/index.html'; | |
const server = express() | |
.use((req, res) => res.sendFile(INDEX, { root: __dirname })) | |
.listen(PORT, () => console.log(`Listening on ${PORT}`)); | |
const io = socketIO(server); | |
io.on('connection', (socket) => { | |
console.log('Client connected'); | |
socket.on('disconnect', () => console.log('Client disconnected')); | |
}); | |
setInterval(() => io.emit('time', new Date().toTimeString()), 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment