synchronous code
Code that runs start to finish without pausing, so the next line waits for it to complete.
In more detail
Methods ending in Sync, such as fs.readFileSync() or zlib.gzipSync(), are synchronous and block the event loop while they run. They are fine in small scripts and start-up code but slow down servers handling many requests.
Related terms
- blocking I/O — An operation that makes the program stop and wait until it finishes, so nothing else on that thread can run meanwhile.
- asynchronous I/O — Starting an input or output operation and carrying on with other work, being told later, usually through a callback or promise, when it has finished.
Taught in
- Timers Phase: setTimeout, Min-Heap Scheduling & Drift — Node.js Internals & Backend Services
- Native Compression: node:zlib & Streaming Codecs — Node.js Internals & Backend Services
- Global Error Trapping: uncaughtException & Exits — Node.js Internals & Backend Services