Skip to main content

Posts

Showing posts with the label node.js Event Emitter errors

Node.js EventEmitter - Error Handling

What is callback? What is error first callback? In Node.js, EventEmitter is use to “emit” an errors and also when your object emits lots of types of events. There are multiple objects that inherit from EventEmitter and the “error” events emitted in Node objects looks like, 1.       Streams 2.       Servers 3.       Requests and Responses 4.       Child Processes etc. Example, //EventEmitter to “emit” errors. var emitr = new (require( 'events' ).EventEmitter)(); //Calling asyncEmitter method. var event = asyncEmitter(); //This method is called, when an "error" event is emitted! event .on( "error" , function (error) { console .error (error); //console.trace(error); }); // This is used to emits the "error" event and return it. var asyncEmitter = function () { process.nextTick( function (){ emitr.emit( "error" , new Er...