Creator of node.js

Node.js EventEmitter - Error Handling

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.

//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) {

// This is used to emits the "error" event and return it.
var asyncEmitter = function() {
        emitr.emit("error", new Error("Here something went wrong!"));
    return emitr;
The EventEmitter will help you all to write the event based Node modules and also your knowledge of EventEmitter will greatly affect your efficiency Node.js carrier.


I hope this post is helpful to you guys! Thank you!

Hey! I'm Anil Singh. I author this blog. I'm Active Blogger, Programmer. I love learning new technologies, programming, blogging and participating the forum discussions more...
My Blogs - and
My Books - Google Amazon and Flipkart Book Store!

You Might Also Like
Post a Comment Powered by Blogger.
ASK Questions
SQL Server NodeJs TypeScript JavaScript Angular SQL Server My Book