
Domains
Agile Management
Master Agile methodologies for efficient and timely project delivery.
View All Agile Management Coursesicon-refresh-cwCertifications
Scrum Alliance
16 Hours
Best Seller
Certified ScrumMaster (CSM) CertificationScrum Alliance
16 Hours
Best Seller
Certified Scrum Product Owner (CSPO) CertificationScaled Agile
16 Hours
Trending
Leading SAFe 6.0 CertificationScrum.org
16 Hours
Professional Scrum Master (PSM) CertificationScaled Agile
16 Hours
SAFe 6.0 Scrum Master (SSM) CertificationAdvanced Certifications
Scaled Agile, Inc.
32 Hours
Recommended
Implementing SAFe 6.0 (SPC) CertificationScaled Agile, Inc.
24 Hours
SAFe 6.0 Release Train Engineer (RTE) CertificationScaled Agile, Inc.
16 Hours
Trending
SAFe® 6.0 Product Owner/Product Manager (POPM)IC Agile
24 Hours
ICP Agile Certified Coaching (ICP-ACC)Scrum.org
16 Hours
Professional Scrum Product Owner I (PSPO I) TrainingMasters
32 Hours
Trending
Agile Management Master's Program32 Hours
Agile Excellence Master's ProgramOn-Demand Courses
Agile and ScrumRoles
Scrum MasterTech Courses and Bootcamps
Full Stack Developer BootcampAccreditation Bodies
Scrum AllianceTop Resources
Scrum TutorialProject Management
Gain expert skills to lead projects to success and timely completion.
View All Project Management Coursesicon-standCertifications
PMI
36 Hours
Best Seller
Project Management Professional (PMP) CertificationAxelos
32 Hours
PRINCE2 Foundation & Practitioner CertificationAxelos
16 Hours
PRINCE2 Foundation CertificationAxelos
16 Hours
PRINCE2 Practitioner CertificationSkills
Change ManagementMasters
Job Oriented
45 Hours
Trending
Project Management Master's ProgramUniversity Programs
45 Hours
Trending
Project Management Master's ProgramOn-Demand Courses
PRINCE2 Practitioner CourseRoles
Project ManagerAccreditation Bodies
PMITop Resources
Theories of MotivationCloud Computing
Learn to harness the cloud to deliver computing resources efficiently.
View All Cloud Computing Coursesicon-cloud-snowingCertifications
AWS
32 Hours
Best Seller
AWS Certified Solutions Architect - AssociateAWS
32 Hours
AWS Cloud Practitioner CertificationAWS
24 Hours
AWS DevOps CertificationMicrosoft
16 Hours
Azure Fundamentals CertificationMicrosoft
24 Hours
Best Seller
Azure Administrator CertificationMicrosoft
45 Hours
Recommended
Azure Data Engineer CertificationMicrosoft
32 Hours
Azure Solution Architect CertificationMicrosoft
40 Hours
Azure DevOps CertificationAWS
24 Hours
Systems Operations on AWS Certification TrainingAWS
24 Hours
Developing on AWSMasters
Job Oriented
48 Hours
New
AWS Cloud Architect Masters ProgramBootcamps
Career Kickstarter
100 Hours
Trending
Cloud Engineer BootcampRoles
Cloud EngineerOn-Demand Courses
AWS Certified Developer Associate - Complete GuideAuthorized Partners of
AWSTop Resources
Scrum TutorialIT Service Management
Understand how to plan, design, and optimize IT services efficiently.
View All DevOps Coursesicon-git-commitCertifications
Axelos
16 Hours
Best Seller
ITIL 4 Foundation CertificationAxelos
16 Hours
ITIL Practitioner CertificationPeopleCert
16 Hours
ISO 14001 Foundation CertificationPeopleCert
16 Hours
ISO 20000 CertificationPeopleCert
24 Hours
ISO 27000 Foundation CertificationAxelos
24 Hours
ITIL 4 Specialist: Create, Deliver and Support TrainingAxelos
24 Hours
ITIL 4 Specialist: Drive Stakeholder Value TrainingAxelos
16 Hours
ITIL 4 Strategist Direct, Plan and Improve TrainingOn-Demand Courses
ITIL 4 Specialist: Create, Deliver and Support ExamTop Resources
ITIL Practice TestData Science
Unlock valuable insights from data with advanced analytics.
View All Data Science Coursesicon-dataBootcamps
Job Oriented
6 Months
Trending
Data Science BootcampJob Oriented
289 Hours
Data Engineer BootcampJob Oriented
6 Months
Data Analyst BootcampJob Oriented
288 Hours
New
AI Engineer BootcampSkills
Data Science with PythonRoles
Data ScientistOn-Demand Courses
Data Analysis Using ExcelTop Resources
Machine Learning TutorialDevOps
Automate and streamline the delivery of products and services.
View All DevOps Coursesicon-terminal-squareCertifications
DevOps Institute
16 Hours
Best Seller
DevOps Foundation CertificationCNCF
32 Hours
New
Certified Kubernetes AdministratorDevops Institute
16 Hours
Devops LeaderSkills
KubernetesRoles
DevOps EngineerOn-Demand Courses
CI/CD with Jenkins XGlobal Accreditations
DevOps InstituteTop Resources
Top DevOps ProjectsBI And Visualization
Understand how to transform data into actionable, measurable insights.
View All BI And Visualization Coursesicon-microscopeBI and Visualization Tools
Certification
24 Hours
Recommended
Tableau CertificationCertification
24 Hours
Data Visualization with Tableau CertificationMicrosoft
24 Hours
Best Seller
Microsoft Power BI CertificationTIBCO
36 Hours
TIBCO Spotfire TrainingCertification
30 Hours
Data Visualization with QlikView CertificationCertification
16 Hours
Sisense BI CertificationOn-Demand Courses
Data Visualization Using Tableau TrainingTop Resources
Python Data Viz LibsCyber Security
Understand how to protect data and systems from threats or disasters.
View All Cyber Security Coursesicon-refresh-cwCertifications
CompTIA
40 Hours
Best Seller
CompTIA Security+EC-Council
40 Hours
Certified Ethical Hacker (CEH v12) CertificationISACA
22 Hours
Certified Information Systems Auditor (CISA) CertificationISACA
40 Hours
Certified Information Security Manager (CISM) Certification(ISC)²
40 Hours
Certified Information Systems Security Professional (CISSP)(ISC)²
40 Hours
Certified Cloud Security Professional (CCSP) Certification16 Hours
Certified Information Privacy Professional - Europe (CIPP-E) CertificationISACA
16 Hours
COBIT5 Foundation16 Hours
Payment Card Industry Security Standards (PCI-DSS) CertificationOn-Demand Courses
CISSPTop Resources
Laptops for IT SecurityWeb Development
Learn to create user-friendly, fast, and dynamic web applications.
View All Web Development Coursesicon-codeBootcamps
Career Kickstarter
6 Months
Best Seller
Full-Stack Developer BootcampJob Oriented
3 Months
Best Seller
UI/UX Design BootcampEnterprise Recommended
6 Months
Java Full Stack Developer BootcampCareer Kickstarter
490+ Hours
Front-End Development BootcampCareer Accelerator
4 Months
Backend Development Bootcamp (Node JS)Skills
ReactOn-Demand Courses
Angular TrainingTop Resources
Top HTML ProjectsBlockchain
Understand how transactions and databases work in blockchain technology.
View All Blockchain Coursesicon-stop-squareBlockchain Certifications
40 Hours
Blockchain Professional Certification32 Hours
Blockchain Solutions Architect Certification32 Hours
Blockchain Security Engineer Certification24 Hours
Blockchain Quality Engineer Certification5+ Hours
Blockchain 101 CertificationOn-Demand Courses
NFT Essentials 101: A Beginner's GuideTop Resources
Blockchain Interview QsProgramming
Learn to code efficiently and design software that solves problems.
View All Programming Coursesicon-codeSkills
Python CertificationInterview Prep
Career Accelerator
3 Months
Software Engineer Interview PrepOn-Demand Courses
Data Structures and Algorithms with JavaScriptTop Resources
Python TutorialNode.js is an asynchronous, event-driven, non-blocking I/O application. It is built with a V8 engine along with other node core components like Libuv. Libuv library developed in C++ provides event loop mechanism and I/O API for concurrent operations. Thanks to this multithreading language which helps in handling concurrent tasks. This mechanism makes Node.js an asynchronous event-based platform in which everything is a reaction to an event.

Above diagram gives a glimpse of how Node.Js works and will use it to understand the event loop better. Node.js is a single thread application and all the blocking calls are stored in the call stack and once they are processed they are removed from the call stack. Let's take an example:
When we run a node, line 1 is moved to call stack and executed and then followed up by line 2 and then line 3. A similar thing can be observed if an error is raised then from the error stack, we can know the order of execution.
Node.js provides timer functions globally. We can work with Node.js asynchronously is through using the timing functions. The timing functions setTimeout, clearTimeout, setInterval, and clearInterval work the same way they do in the browser and are available to you globally.
So whenever asynchronous calls are observed during execution, those are moved to API block and the call stack is continued. When the asynchronous operation is done say setTimeout, the execution of call-backs is done by the event loop i.e. it moved the callback of setTimeout to Event Queue. And event loop will be keeping monitoring the call stack to get empty. And once it is empty then call back is pushed to call stack and executed.
Note: Libuv library basically creates a thread pool to offload the asynchronous work. If the operating system provides an interface for I/O tasks then this is used instead of working with threads.
Below are the examples of global timer functions:
App1: Simple example using setTimeout with a callback to log in console.
var waitTime = 3000;
console.log(“wait for it”);
setTimeout(() => console.log(“done”), waitTime);
App2: Extending above example with usage of setInterval along wit
- Let's extend the above one with setInterval function.
- Add a couple more variables say currentTime which we can initialize it to 0 milliseconds and waitInterval with 500 (half a second).
- WaitInterval is used to fire the callback of setInterval every half second.
var waitTime = 3000;
var currentTime = 0;
var waitInterval = 500;
console.log(“wait for it”);
setTimeout(() => console.log(“done”), waitTime);
- setTimeout waits for a delay once and then invokes the callback function, where as setInterval will fire the callback function over and over again on an interval time. Lets add a setInterval.
var waitTime = 3000;
var currentTime = 0;
var waitInterval = 500;
console.log(“wait for it”);
setInterval(() => {
currentTime =+ waitInterval;
console.log(`waiting ${currentTime/1000} seconds…`); // to display in seconds
}, waitInterval);
setTimeout(() => console.log(“done”), waitTime);
- run node timer.js
- We will observe that waiting is keeping incrementing by half second and once we reach 3 seconds, done is displayed.
- Notice that after the done log we are still going. That interval will not stop.
- Lets add an exit criteria after 3 seconds and to stop application hit control C.
- setInterval return has to be set in a variable. And call clearInterval with argument as this variable inside setTimeOut.
var waitTime = 3000;
var currentTime = 0;
var waitInterval = 500;
console.log(“wait for it”);
var interval = setInterval(() => {
currentTime =+ waitInterval;
console.log(`waiting ${currentTime/1000} seconds…`);
}, waitInterval);
setTimeout(() => {
clearInterval(interval);
console.log(“done”)
}, waitTime);
- Now on running node timer.js, we will see that post 3 seconds the application is stopped.
App3:
Let's modify this code to display the time waiting in a percentage and also control the standard output, so that we overwrite the last line, meaning that we can see a percentage number grow.
- Lets add a function for writing the percentage writeWaitingPercent.
function writeWaitingPercent(percent) {
process.stdout.clearLine(); // clears the previous line
process.stdout.cursorTo(0); // moves the cursor to first line
process.stdout.write(`waiting ... ${percent}%`); // add the text to first line
}
- Lets add a variable to percentWaited and set to 0
- Call the writeWaitingPercent with percentWaited at the end of the file
- Also updated the setTimeOut to call this writeWaitingPercent with 100 in callback.
setTimeout(() => {
clearInterval(interval);
writeWaitingPercent(100);
console.log(“done”)
}, waitTime);
- In setInterval callback also, lets call the writeWaitingPercent based on the calculated percentWaited based on currentTime.
var interval = setInterval(() => {
currentTime =+ waitInterval;
percentWaited = Math.floor((currentTime/waitTime) * 100);
writeWaitingPercent(percentWaited);
}, waitInterval);
- Lets run node timer in terminal observe the percentage increase.
- To observe a slow increase we can reduce the waitInterval to much lesser value say 50 milliseconds.
varwaitTime = 3000;
varcurrentTime = 0;
varwaitInterval = 500;
varpercentWaited = 0;
functionwriteWaitingPercent(percent) {
process.stdout.clearLine();
process.stdout.cursorTo(0);
process.stdout.write(`waiting ... ${percent}%`);
}
varinterval = setInterval(function() {
currentTime += waitInterval;
percentWaited = Math.floor((currentTime/waitTime) * 100);
writeWaitingPercent(percentWaited);
}, waitInterval);
setTimeout(function() {
clearInterval(interval);
writeWaitingPercent(100);
console.log("\n\n done \n\n");
}, waitTime);
writeWaitingPercent(percentWaited);
Output:
node timers
waiting ... 100%
done
EventEmitter is another core module which comes along with Node.js. It helps in build a pub sub pattern i.e. to emit and listen to custom events. Lets use this module and understand with the help of an example.
App1:
App2:
One other important about these events is that they are asynchronous and raised when they happen. Let take another example.
const input = data.toString().trim();
emitter.emit(“customEvent”, input, “terminal”);
});
const input = data.toString().trim();
if (input === ‘exit’) {
emitter.emit(“customEvent”, “user has exited”, “terminal”);
process.exit();
}
emitter.emit(“customEvent”, input, “terminal”);
});
App3:
Let's create an object and add event handling mechanism to that object with the help of eventEmitter.
this.name = name;
}
console.log(`${this.name}`: ${msg});
});
varEventEmitter = require('events').EventEmitter;
varutil = require('util');
varPerson = function(name) {
this.name = name;
};
util.inherits(Person, EventEmitter);
varemployee = newPerson("SomePerson");
employee.on('programmer', function(msg) {
console.log(`${this.name}: ${msg}`);
});
employee.emit('programmer', "You are a good learner.");
Output:
SomePerson: You are a good learner.