Question
CS 602 Server Side development hw1c please explain and comment the following node.js code const colors = require('colors'); const EmployeeEmitter = require('./employeeEmitter').EmployeeEmitter; // Usage const
CS 602 Server Side development hw1c please explain and comment the following node.js code
const colors = require('colors');
const EmployeeEmitter = require('./employeeEmitter').EmployeeEmitter;
// Usage const data = [ {id:1, firstName:'John',lastName:'Smith'}, {id:2, firstName:'Jane',lastName:'Smith'}, {id:3, firstName:'John',lastName:'Doe'} ];
const employees = new EmployeeEmitter(data);
employees.on('lookupById', function (args) { console.log(colors.blue('Event lookupById raised! %s'), args); }); employees.on('lookupByLastName', function (args) { console.log(colors.blue('Event lookupByLastName raised! %s'), args); }); employees.on('addEmployee', function (args) { console.log(colors.blue('Event addEmployee raised! %s'), args); });
console.log(" Lookup by last name (Smith)".red); console.log(employees.lookupByLastName('Smith'));
console.log(" Adding employee William Smith".red); employees.addEmployee('William', 'Smith');
console.log(" Lookup by last name (Smith)".red); console.log(employees.lookupByLastName('Smith'));
console.log(" Lookup by id (2)".red); var e2 = employees.lookupById(2); console.log(e2);
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started