Skip to content

Instantly share code, notes, and snippets.

Created Apr 8, 2020
What would you like to do?
WS server
import WebSocket from 'ws';
const webSocketServer = new WebSocket.Server({ server });
webSocketServer.on('error', (err) => logger.error(err));
webSocketServer.on('headers', (headers) => logger.log('headersi', headers));
webSocketServer.on('connection', (ws) => {
logger.log('new connection');
ws.on('open', () => logger.log('open'));
ws.on('close', () => logger.log('closed'));
ws.on('message', (message) => {
logger.log(`WS message: '${message}'`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment