Slip 7 Create a node js file named main.js for event-driven application. There should be a main loop that listens for events, and then triggers a callback function when one of those events is detected.

 // import event module

var events = require('events');


// create an eventEmitter object

var eventEmitter = new events.EventEmitter();


// create an event handler

var connectHandler = function (s) {

   console.log('Its', s);

};


// Bind the data_received event

eventEmitter.on('data_received', function (name) {

   console.log(name, "Understood event -Driven");

});


// trigger data_received event

eventEmitter.emit('data_received', "FYMSC(CS)");


// Bind the connection event

eventEmitter.on('connection', connectHandler);


// trigger connection event

eventEmitter.emit('connection', "SIMPLE SOLUTION");


console.log("program Ended");


Comments

Popular posts from this blog

Slip 11: Write node js application that transfer a file as an attachment on web and enables browser to prompt the user to download file using express js.

Slip 1(a) Write an Angular 13 application addition of two numbers using ng-init, ng-model & ng-bind. And also demonstrate ng-show, ng-disabled, ng-click directives on button component.