Tuesday, 30 May 2017

NodeJS emit event is not firing

I have this NodeJS code, and I have no idea why the emit function is not firing, It only fires when I put it inside a callback function like setTimeout

const url = require('url');
const WebSocket = require('ws');
const EventEmitter = require('events');

WebSocketServer = new EventEmitter();

WebSocketServer.start =  (server) => {
    const wss = new WebSocket.Server({server});
    console.log('websocket started');
    WebSocketServer.emit('started');
};

module.exports = WebSocketServer;



via Oz Bar-Shalom

No comments:

Post a Comment