Performance: Reading files with promises (fs.promises)
MEDIUM IMPACT
This affects how quickly file data is read and made available without blocking the main event loop, improving server responsiveness.
import { promises as fs } from 'fs'; async function readFile() { const data = await fs.readFile('file.txt', 'utf8'); console.log(data); } readFile();
const fs = require('fs'); const data = fs.readFileSync('file.txt', 'utf8'); console.log(data);
| Pattern | Event Loop Blocking | Throughput Impact | Responsiveness | Verdict |
|---|---|---|---|---|
| Synchronous fs.readFileSync | Blocks event loop | Reduces throughput | Poor (blocks input) | [X] Bad |
| Asynchronous fs.promises.readFile | Non-blocking | Improves throughput | Good (responsive) | [OK] Good |