The Node.js Non-Blocking Event Loop
Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient for real-time web applications.
const fs = require('fs/promises');
async function readFileExample() {
try {
// Asynchronous non-blocking file read
const data = await fs.readFile('package.json', 'utf8');
console.log('File content loaded without blocking the event loop!');
} catch (err) {
console.error('Error reading file:', err);
}
}
readFileExample();