Menu

1 / 2

Blocking vs Non-Blocking Code in Node.js Blocking vs Non-Blocking Code in Node.js

DEV Community·Pratham·6 months ago
#S5sPp1kv
#blocking#nonblocking#part#const#server
Reading 0:00
15s threshold

The difference between a server that freezes under load and one that handles thousands of users effortlessly.

Let me show you two versions of the same server. Both read a file and send it to the client. Both produce the correct result. But one can handle 10,000 users and the other chokes at 50.

// Version A — blocking const data = fs . readFileSync ( " large-file.txt " , " utf8 " ); res . send ( data );

// Version B — non-blocking fs . readFile ( " large-file.txt " , " utf8 " , ( err , data ) => { res . send ( data ); });

Enter fullscreen mode

Exit fullscreen mode

The only difference? readFileSync vs readFile . One letter — Sync — and your server's ability to handle concurrent users goes from thousands to barely any.

Understanding why this matters is one of the most important things I've learned about Node.js in the ChaiCode Web Dev Cohort 2026.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.