Nearby lessons
8 of 21⚡ Node.js – Synchronous vs Asynchronous
📌 What are Sync vs Async?
What is Synchronous and Asynchronous in Node.js?
This tutorial explains the difference between synchronous (blocking) and asynchronous (non-blocking) architectures, and how Node.js handles them.
🟢 Synchronous
Synchronous is a blocking architecture, so the execution of each operation depends on completing the one before it.
Each task requires an answer before moving on to the next iteration.
Each task requires an answer before moving on to the next iteration.
🔵 Asynchronous
Asynchronous is a non-blocking architecture, so the execution of one task isn't dependent on another.
Tasks can run simultaneously (parallel).
Tasks can run simultaneously (parallel).
⚖️ Synchronous VS Asynchronous
- Async is multi-threaded; operations can run in parallel.
- Sync is single-threaded; only one operation runs at a time.
- Async is non-blocking; it can send multiple requests to a server.
- Sync is blocking; it sends one request at a time and waits for a response.
- Async increases throughput because multiple operations can run simultaneously.
- Sync is slower and more methodical.
❓ Is Node.js Sync or Async?
Node.js primarily follows an Asynchronous model, but synchronous methods are also available when needed.
Node.js Environment
RUNTIME ACTIVE
const fs = require('fs'); console.log("--- START ---"); // Asynchronous read (non-blocking) fs.readFile('./package.json', 'utf8', (err, data) => { console.log("Async Read Finished"); }); console.log("--- END (Main thread) ---");
Terminal Output
🧠 Test Your Knowledge
4 QuestionsProgress: 0 / 4
Keep Going!File System (FS) Module in Node.js