Skip to content

Instantly share code, notes, and snippets.



Last active Mar 30, 2020
What would you like to do?
Node Websocket Server Base
'use strict';
const express = require('express');
const socketIO = require('');
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
You can’t perform that action at this time.