Performance: Reading files synchronously
HIGH IMPACT
This affects the main thread blocking time, delaying other operations and slowing overall responsiveness.
const fs = require('fs'); fs.readFile('file.txt', 'utf8', (err, data) => { if (err) throw err; console.log(data); });
const fs = require('fs'); const data = fs.readFileSync('file.txt', 'utf8'); console.log(data);
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Synchronous file read | N/A | Blocks event loop, no DOM changes during read | Delays paint and input handling | [X] Bad |
| Asynchronous file read | N/A | Event loop remains free | Paint and input handled promptly | [OK] Good |