Node.js events handle connection event

Description

Node.js events handle connection event


var events = require('events');

var eventEmitter = new events.EventEmitter();

var connectHandler = function connected(){
  console.log('connected');
    /*from  w  w  w.  j  a v a2  s.  c  o  m*/
  eventEmitter.emit('data_received');
}

eventEmitter.on('connection',connectHandler);

eventEmitter.on('data_received',function(){
  console.log('data recevied');
});

eventEmitter.emit('connection');

console.log('Over');



PreviousNext

Related