Non-blocking I/O means Node.js starts an I/O operation and keeps running other code instead of waiting for it to finish. Reading a file, querying a database and calling another server all work this way. When the result is ready, the event loop runs the callback you passed, or resumes the function that awaited the promise.
// Non-blocking example
const fs = require('fs');
console.log('Start reading file');
fs.readFile('large-file.txt', (err, data) => {
console.log('File read complete');
});
console.log('This executes immediately');
// Output: Start reading file, This executes immediately, File read complete
This executes immediately prints before File read complete, because readFile returns at once and its callback runs later. The main thread never sits idle waiting on a disk or the network. That is how a single Node.js process handles thousands of concurrent connections.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
The diagram below the answer is the concept . Jump to it ↓