Node.js Event Loop
Node.js is a single-threaded event-driven platform that is capable of running non-blocking, asynchronously programming.
it can support concurrency via the concept of event and callbacks.
The event loop allows Node.js to perform non-blocking I/O operations despite the fact that JavaScript is single-threaded.
Node.js Event Loop that listens for events, and then triggers a callback function when one of those events is detected.
The event loop executes tasks from the event queue only when the call stack is empty.
Syntax
var events = require('events'); // import events module to handle events
var eventEmitter = new events.EventEmitter(); //Create an eventEmitter object
eventEmitter.on('eventName', eventHandler); // create event
eventEmitter.emit('eventName'); // fire event
Comments