addEventListener in node js code example

Example 1: js addeventlistener

document.getElementById("example").addEventListener('click', function() {
  alert('Click');
});

Example 2: js addeventlistener

var element=document.getElementById("some_id");
var listener=element.addEventListener('click',function(event){                          
            
 });

Example 3: node js event emitter

const EventEmitter = require('events');

class MyEmitter extends EventEmitter {
  foo() {
    this.emit('test');
  }
}
const myEmitter = new MyEmitter();
myEmitter.on('test', () => console.log('Yay, it works!'));

myEmitter.foo();	// Yay it works!

Example 4: eventemitter nodejs

myEmitter.on('status', (code, msg)=> console.log(`Got ${code} and ${msg}`));