{"id":70,"date":"2019-09-22T08:05:42","date_gmt":"2019-09-22T08:05:42","guid":{"rendered":"https:\/\/www.kindsonthegenius.com\/nodejs\/?p=70"},"modified":"2020-08-06T09:56:08","modified_gmt":"2020-08-06T09:56:08","slug":"node-js-eventemitter","status":"publish","type":"post","link":"https:\/\/www.kindsonthegenius.com\/nodejs\/node-js-eventemitter\/","title":{"rendered":"Node.js &#8211; EventEmitter"},"content":{"rendered":"<p>As you know from <a href=\"https:\/\/www.kindsonthegenius.com\/nodejs\/07-node-js-event-loops\/\">Tutorial 6(Event Loop)<\/a>, Node.js is an event-driven program. Therefore, actions emit events.<\/p>\n<p>For example:<\/p>\n<ul>\n<li>when a file if opened<\/li>\n<li>when a connection is made<\/li>\n<li>when a file is closed<\/li>\n<\/ul>\n<p>In Node.js, objects can fire events. For example the readStream object can fire events when opening or closing a file.<\/p>\n<p>This is shown below<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008800; font-weight: bold;\">var<\/span> fs <span style=\"color: #333333;\">=<\/span> require(<span style=\"background-color: #fff0f0;\">\"fs\"<\/span>);\r\npath <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">\"D:\/nodefiles\/testinput.txt\"<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">var<\/span> readStream <span style=\"color: #333333;\">=<\/span> fs.createReadStream(path);\r\nreadStream.on(<span style=\"background-color: #fff0f0;\">\"open\"<\/span>, <span style=\"color: #008800; font-weight: bold;\">function<\/span>(){\r\n    console.log(<span style=\"background-color: #fff0f0;\">\"A file has been opened\"<\/span>);\r\n});\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>Objects that emit events are instances of the events.EventEmitter class. Let&#8217;s now talk about EventEmitter.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>The EventEmitter Class<\/strong><\/p>\n<p>The EventEmitter class is defined in the events module. So to use it, you need to require the events module. In this way, you can create your own EventEmitter objects. The code below creates a new eventEmitter object.<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #888888;\">\/\/import the events module<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">var<\/span> events <span style=\"color: #333333;\">=<\/span> require(<span style=\"background-color: #fff0f0;\">\"events\"<\/span>);\r\n\r\n<span style=\"color: #888888;\">\/\/create an EventEmitter object<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">var<\/span> eventEmitter <span style=\"color: #333333;\">=<\/span> <span style=\"color: #008800; font-weight: bold;\">new<\/span> events.eventEmitter();\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>An EventEmitter provides a number of properties like the <strong>emit<\/strong> and <strong>on<\/strong>.<\/p>\n<ul>\n<li>the on property binds the event to the handler<\/li>\n<li>the emit property is used to fire the event<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><strong>EventEmitter Methods<\/strong><\/p>\n<p>The table below provide a list of methods for an events.<\/p>\n<table class=\"table table-bordered\">\n<tbody>\n<tr>\n<th>SN.<\/th>\n<th>Method &amp; Brief Description<\/th>\n<\/tr>\n<tr>\n<td class=\"ts\">1<\/td>\n<td><b>addListener(event, listener)<\/b><\/p>\n<p>Adds a listener to the listeners array for the given event. No checks are made to see if the listener has already been added. Multiple calls passing the same combination of event and listener will result in the listener being added multiple times. It returns emitter, hence calls can be chained.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">2<\/td>\n<td><b>on(event, listener)<\/b><\/p>\n<p>Adds a listener at the end of the listeners array for the given event. It doesn&#8217;t check if the listener has already been added. Multiple calls passing the same combination of event and listener will mean that the\u00a0 listener can be added multiple times. Emitter is returned, therefore calls can be chained.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">3<\/td>\n<td><b>once(event, listener)<\/b><\/p>\n<p>Adds a one time listener to the event. This listener is invoked only the next time the event is fired, after which it is removed. Returns emitter, so calls can be chained.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">4<\/td>\n<td><b>removeListener(event, listener)<\/b><\/p>\n<p>Removes a listener from the listener array for the specified event.\u00a0<b>Caution \u2212<\/b> It changes the array indices in the listener array behind the listener. removeListener will remove, at most, one instance of a listener from the listener array. If any single listener has been added multiple times to the listener array for the specified event, then removeListener must be called multiple times to remove each instance. Returns emitter, hence calls can be chained.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">5<\/td>\n<td><b>removeAllListeners([event])<\/b><\/p>\n<p>Removes all the listeners, or those of the given event. It&#8217;s not a good idea to remove listeners that were added elsewhere in the code, especially when it&#8217;s on an emitter you didn&#8217;t create (e.g. sockets or file streams). Returns emitter, hence calls can be chained.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">6<\/td>\n<td><b>setMaxListeners(n)<\/b><\/p>\n<p>EventEmitters, by default will print a warning if more than 10 listeners are added for a particular event. This is useful because helps finding memory leaks. Granted. not all Emitters should be limited to only 10 listeners. This function makes it possible for that to be increased. To be unlimited, then set it to zero.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">7<\/td>\n<td><b>listeners(event)<\/b><\/p>\n<p>Returns an array of listeners for the specified event.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">8<\/td>\n<td><b>emit(event, [arg1], [arg2], [&#8230;])<\/b><\/p>\n<p>This method executes each of the listeners in order with the supplied arguments. It returns true if the event had listeners, else it returns false.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p><strong>Class Methods<\/strong><\/p>\n<p>One class method in the EventEmitter class is given below:<\/p>\n<table class=\"table table-bordered\">\n<tbody>\n<tr>\n<th>SN.<\/th>\n<th>Method brief\u00a0 description<\/th>\n<\/tr>\n<tr>\n<td class=\"ts\">1<\/td>\n<td><b>listenerCount(emitter, event)<\/b><\/p>\n<p>This method returns the number of listeners for a specified event.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p><strong>Events<\/strong><\/p>\n<p>Some events provided by the EventEmitter class are given below<\/p>\n<table class=\"table table-bordered\">\n<tbody>\n<tr>\n<th>SNo.<\/th>\n<th>Events and brief description<\/th>\n<\/tr>\n<tr>\n<td class=\"ts\">1<\/td>\n<td><b>newListener<\/b><\/p>\n<ul>\n<li><b>event<\/b> \u2212 String: the name of the event<\/li>\n<li><b>listener<\/b> \u2212 Function: this is the event-handler function<\/li>\n<\/ul>\n<p>Any time a listener is added, t<span style=\"font-family: inherit; font-size: inherit;\">his event is emitted. However, w<\/span><span style=\"font-family: inherit; font-size: inherit;\">hen it is triggered, the listener may not yet have been added to the array of listeners for the event.<\/span><\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">2<\/td>\n<td><b>removeListener<\/b><\/p>\n<ul>\n<li><b>event<\/b> \u2212 String The name of the event<\/li>\n<li><b>listener<\/b> \u2212 Function The event-handler function<\/li>\n<\/ul>\n<p>This event is emitted any time a listener is removed. However, when it is triggered, the listener may not yet have been removed from the array of listeners for the event.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p><strong>An Example<\/strong><\/p>\n<p>The code below illustrates how EventEmitters work.<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #888888;\">\/\/Program to illustrate EventEmitter<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">var<\/span> events <span style=\"color: #333333;\">=<\/span> require(<span style=\"background-color: #fff0f0;\">'events'<\/span>);\r\n<span style=\"color: #008800; font-weight: bold;\">var<\/span> eventEmitter <span style=\"color: #333333;\">=<\/span> <span style=\"color: #008800; font-weight: bold;\">new<\/span> events.EventEmitter();\r\n\r\n<span style=\"color: #888888;\">\/\/ listener 1<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">var<\/span> listner_1 <span style=\"color: #333333;\">=<\/span> <span style=\"color: #008800; font-weight: bold;\">function<\/span> listner_1() {\r\n   console.log(<span style=\"background-color: #fff0f0;\">'listner_1 executed.'<\/span>);\r\n}\r\n\r\n<span style=\"color: #888888;\">\/\/ listener 2<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">var<\/span> listner_2 <span style=\"color: #333333;\">=<\/span> <span style=\"color: #008800; font-weight: bold;\">function<\/span> listner_2() {\r\n   console.log(<span style=\"background-color: #fff0f0;\">'listner_2 executed.'<\/span>);\r\n}\r\n\r\n<span style=\"color: #888888;\">\/\/ Bind the connection event with the listner_1 function<\/span>\r\neventEmitter.addListener(<span style=\"background-color: #fff0f0;\">'connection'<\/span>, listner_1);\r\n\r\n<span style=\"color: #888888;\">\/\/ Bind the connection event with the listner_2 function<\/span>\r\neventEmitter.on(<span style=\"background-color: #fff0f0;\">'connection'<\/span>, listner_2);\r\n\r\n<span style=\"color: #008800; font-weight: bold;\">var<\/span> eventListeners <span style=\"color: #333333;\">=<\/span> require(<span style=\"background-color: #fff0f0;\">'events'<\/span>).EventEmitter.listenerCount\r\n   (eventEmitter,<span style=\"background-color: #fff0f0;\">'connection'<\/span>);\r\nconsole.log(eventListeners <span style=\"color: #333333;\">+<\/span> <span style=\"background-color: #fff0f0;\">\" Listner(s) listening to connection event\"<\/span>);\r\n\r\n<span style=\"color: #888888;\">\/\/ Fire the connection event <\/span>\r\neventEmitter.emit(<span style=\"background-color: #fff0f0;\">'connection'<\/span>);\r\n\r\n<span style=\"color: #888888;\">\/\/ Remove the binding of listner_1 function<\/span>\r\neventEmitter.removeListener(<span style=\"background-color: #fff0f0;\">'connection'<\/span>, listner_1);\r\nconsole.log(<span style=\"background-color: #fff0f0;\">\"Listner_1 will not listen now.\"<\/span>);\r\n\r\n<span style=\"color: #888888;\">\/\/ Fire the connection event <\/span>\r\neventEmitter.emit(<span style=\"background-color: #fff0f0;\">'connection'<\/span>);\r\n\r\neventListeners <span style=\"color: #333333;\">=<\/span> require(<span style=\"background-color: #fff0f0;\">'events'<\/span>).EventEmitter.listenerCount(eventEmitter,<span style=\"background-color: #fff0f0;\">'connection'<\/span>);\r\nconsole.log(eventListeners <span style=\"color: #333333;\">+<\/span> <span style=\"background-color: #fff0f0;\">\" Listner(s) listening to connection event\"<\/span>);\r\n\r\nconsole.log(<span style=\"background-color: #fff0f0;\">\"Program Ended.\"<\/span>);\r\n<\/pre>\n<p>The output of the code is given below<\/p>\n<figure id=\"attachment_78\" aria-describedby=\"caption-attachment-78\" style=\"width: 699px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/kindsonthegenius.com\/nodejs\/wp-content\/uploads\/sites\/5\/2019\/09\/Event-Emitter-Listener-Output.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-78\" src=\"https:\/\/kindsonthegenius.com\/nodejs\/wp-content\/uploads\/sites\/5\/2019\/09\/Event-Emitter-Listener-Output.jpg\" alt=\"Event Emitter Listener Output\" width=\"699\" height=\"278\" srcset=\"https:\/\/www.kindsonthegenius.com\/nodejs\/wp-content\/uploads\/sites\/5\/2019\/09\/Event-Emitter-Listener-Output.jpg 699w, https:\/\/www.kindsonthegenius.com\/nodejs\/wp-content\/uploads\/sites\/5\/2019\/09\/Event-Emitter-Listener-Output-300x119.jpg 300w\" sizes=\"auto, (max-width: 699px) 100vw, 699px\" \/><\/a><figcaption id=\"caption-attachment-78\" class=\"wp-caption-text\">Event Emitter Listener Output<\/figcaption><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>As you know from Tutorial 6(Event Loop), Node.js is an event-driven program. Therefore, actions emit events. For example: when a file if opened when a &hellip; <\/p>\n","protected":false},"author":1,"featured_media":75,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-70","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Node.js - EventEmitter - Node.js Tutorials<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.kindsonthegenius.com\/nodejs\/node-js-eventemitter\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Node.js - EventEmitter - Node.js Tutorials\" \/>\n<meta property=\"og:description\" content=\"As you know from Tutorial 6(Event Loop), Node.js is an event-driven program. Therefore, actions emit events. For example: when a file if opened when a &hellip;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.kindsonthegenius.com\/nodejs\/node-js-eventemitter\/\" \/>\n<meta property=\"og:site_name\" content=\"Node.js Tutorials\" \/>\n<meta property=\"article:published_time\" content=\"2019-09-22T08:05:42+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-08-06T09:56:08+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.kindsonthegenius.com\/nodejs\/wp-content\/uploads\/sites\/5\/2019\/09\/EventEmitter-in-Node.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"879\" \/>\n\t<meta property=\"og:image:height\" content=\"334\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"kindsonthegenius\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"kindsonthegenius\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/node-js-eventemitter\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/node-js-eventemitter\\\/\"},\"author\":{\"name\":\"kindsonthegenius\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/#\\\/schema\\\/person\\\/7f8fc5792578d2ff54003fcebe6c46b5\"},\"headline\":\"Node.js &#8211; EventEmitter\",\"datePublished\":\"2019-09-22T08:05:42+00:00\",\"dateModified\":\"2020-08-06T09:56:08+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/node-js-eventemitter\\\/\"},\"wordCount\":709,\"commentCount\":1,\"image\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/node-js-eventemitter\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/wp-content\\\/uploads\\\/sites\\\/5\\\/2019\\\/09\\\/EventEmitter-in-Node.jpg\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/node-js-eventemitter\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/node-js-eventemitter\\\/\",\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/node-js-eventemitter\\\/\",\"name\":\"Node.js - EventEmitter - Node.js Tutorials\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/node-js-eventemitter\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/node-js-eventemitter\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/wp-content\\\/uploads\\\/sites\\\/5\\\/2019\\\/09\\\/EventEmitter-in-Node.jpg\",\"datePublished\":\"2019-09-22T08:05:42+00:00\",\"dateModified\":\"2020-08-06T09:56:08+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/#\\\/schema\\\/person\\\/7f8fc5792578d2ff54003fcebe6c46b5\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/node-js-eventemitter\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/node-js-eventemitter\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/node-js-eventemitter\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/wp-content\\\/uploads\\\/sites\\\/5\\\/2019\\\/09\\\/EventEmitter-in-Node.jpg\",\"contentUrl\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/wp-content\\\/uploads\\\/sites\\\/5\\\/2019\\\/09\\\/EventEmitter-in-Node.jpg\",\"width\":879,\"height\":334,\"caption\":\"EventEmitter in Node\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/node-js-eventemitter\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Node.js &#8211; EventEmitter\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/#website\",\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/\",\"name\":\"Node.js Tutorials\",\"description\":\"Best Node.js Tutorials\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/#\\\/schema\\\/person\\\/7f8fc5792578d2ff54003fcebe6c46b5\",\"name\":\"kindsonthegenius\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g\",\"caption\":\"kindsonthegenius\"},\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/nodejs\\\/author\\\/kindsonthegenius-3\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Node.js - EventEmitter - Node.js Tutorials","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.kindsonthegenius.com\/nodejs\/node-js-eventemitter\/","og_locale":"en_US","og_type":"article","og_title":"Node.js - EventEmitter - Node.js Tutorials","og_description":"As you know from Tutorial 6(Event Loop), Node.js is an event-driven program. Therefore, actions emit events. For example: when a file if opened when a &hellip;","og_url":"https:\/\/www.kindsonthegenius.com\/nodejs\/node-js-eventemitter\/","og_site_name":"Node.js Tutorials","article_published_time":"2019-09-22T08:05:42+00:00","article_modified_time":"2020-08-06T09:56:08+00:00","og_image":[{"width":879,"height":334,"url":"https:\/\/www.kindsonthegenius.com\/nodejs\/wp-content\/uploads\/sites\/5\/2019\/09\/EventEmitter-in-Node.jpg","type":"image\/jpeg"}],"author":"kindsonthegenius","twitter_card":"summary_large_image","twitter_misc":{"Written by":"kindsonthegenius","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.kindsonthegenius.com\/nodejs\/node-js-eventemitter\/#article","isPartOf":{"@id":"https:\/\/www.kindsonthegenius.com\/nodejs\/node-js-eventemitter\/"},"author":{"name":"kindsonthegenius","@id":"https:\/\/www.kindsonthegenius.com\/nodejs\/#\/schema\/person\/7f8fc5792578d2ff54003fcebe6c46b5"},"headline":"Node.js &#8211; EventEmitter","datePublished":"2019-09-22T08:05:42+00:00","dateModified":"2020-08-06T09:56:08+00:00","mainEntityOfPage":{"@id":"https:\/\/www.kindsonthegenius.com\/nodejs\/node-js-eventemitter\/"},"wordCount":709,"commentCount":1,"image":{"@id":"https:\/\/www.kindsonthegenius.com\/nodejs\/node-js-eventemitter\/#primaryimage"},"thumbnailUrl":"https:\/\/www.kindsonthegenius.com\/nodejs\/wp-content\/uploads\/sites\/5\/2019\/09\/EventEmitter-in-Node.jpg","inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.kindsonthegenius.com\/nodejs\/node-js-eventemitter\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.kindsonthegenius.com\/nodejs\/node-js-eventemitter\/","url":"https:\/\/www.kindsonthegenius.com\/nodejs\/node-js-eventemitter\/","name":"Node.js - EventEmitter - Node.js Tutorials","isPartOf":{"@id":"https:\/\/www.kindsonthegenius.com\/nodejs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.kindsonthegenius.com\/nodejs\/node-js-eventemitter\/#primaryimage"},"image":{"@id":"https:\/\/www.kindsonthegenius.com\/nodejs\/node-js-eventemitter\/#primaryimage"},"thumbnailUrl":"https:\/\/www.kindsonthegenius.com\/nodejs\/wp-content\/uploads\/sites\/5\/2019\/09\/EventEmitter-in-Node.jpg","datePublished":"2019-09-22T08:05:42+00:00","dateModified":"2020-08-06T09:56:08+00:00","author":{"@id":"https:\/\/www.kindsonthegenius.com\/nodejs\/#\/schema\/person\/7f8fc5792578d2ff54003fcebe6c46b5"},"breadcrumb":{"@id":"https:\/\/www.kindsonthegenius.com\/nodejs\/node-js-eventemitter\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.kindsonthegenius.com\/nodejs\/node-js-eventemitter\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.kindsonthegenius.com\/nodejs\/node-js-eventemitter\/#primaryimage","url":"https:\/\/www.kindsonthegenius.com\/nodejs\/wp-content\/uploads\/sites\/5\/2019\/09\/EventEmitter-in-Node.jpg","contentUrl":"https:\/\/www.kindsonthegenius.com\/nodejs\/wp-content\/uploads\/sites\/5\/2019\/09\/EventEmitter-in-Node.jpg","width":879,"height":334,"caption":"EventEmitter in Node"},{"@type":"BreadcrumbList","@id":"https:\/\/www.kindsonthegenius.com\/nodejs\/node-js-eventemitter\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.kindsonthegenius.com\/nodejs\/"},{"@type":"ListItem","position":2,"name":"Node.js &#8211; EventEmitter"}]},{"@type":"WebSite","@id":"https:\/\/www.kindsonthegenius.com\/nodejs\/#website","url":"https:\/\/www.kindsonthegenius.com\/nodejs\/","name":"Node.js Tutorials","description":"Best Node.js Tutorials","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.kindsonthegenius.com\/nodejs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.kindsonthegenius.com\/nodejs\/#\/schema\/person\/7f8fc5792578d2ff54003fcebe6c46b5","name":"kindsonthegenius","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g","caption":"kindsonthegenius"},"url":"https:\/\/www.kindsonthegenius.com\/nodejs\/author\/kindsonthegenius-3\/"}]}},"_links":{"self":[{"href":"https:\/\/www.kindsonthegenius.com\/nodejs\/wp-json\/wp\/v2\/posts\/70","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kindsonthegenius.com\/nodejs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kindsonthegenius.com\/nodejs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/nodejs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/nodejs\/wp-json\/wp\/v2\/comments?post=70"}],"version-history":[{"count":5,"href":"https:\/\/www.kindsonthegenius.com\/nodejs\/wp-json\/wp\/v2\/posts\/70\/revisions"}],"predecessor-version":[{"id":122,"href":"https:\/\/www.kindsonthegenius.com\/nodejs\/wp-json\/wp\/v2\/posts\/70\/revisions\/122"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/nodejs\/wp-json\/wp\/v2\/media\/75"}],"wp:attachment":[{"href":"https:\/\/www.kindsonthegenius.com\/nodejs\/wp-json\/wp\/v2\/media?parent=70"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/nodejs\/wp-json\/wp\/v2\/categories?post=70"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/nodejs\/wp-json\/wp\/v2\/tags?post=70"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}