The two patterns that make Node.js non-blocking — and how one evolved from the other. Every Node.js developer faces this moment: you write what looks like perfectly logical code, and the output comes in the wrong order. const fs = require ( " fs " ); console . log ( " Before reading file " ); fs . readFile ( " data.txt " , " utf8 " , ( err , content ) => { console . log ( " File content: " , content ); }); console . log ( " After reading file " ); Enter fullscreen mode Exit fullscreen mode Output: Before reading file After reading file File content: Hello from data.txt! Enter fullscreen mode Exit fullscreen mode Wait — "After reading file" printed before the file content? The file read is in the middle of the code, but its result came last? Welcome to async Node.js. This isn't a bug. This is exactly how Node.js is designed to work — and understanding why is the key to writing effective server-side JavaScript. Let me walk you through the two async patterns that Node.js is built on: callbacks and Promises .…