Performance: CommonJS require and module.exports
MEDIUM IMPACT
This concept affects server-side module loading speed and initial script execution time in Node.js environments.
import fs from 'fs/promises'; async function readFile() { const data = await fs.readFile('file.txt'); console.log(data.toString()); } readFile();
const fs = require('fs'); const data = fs.readFileSync('file.txt'); console.log(data.toString());
| Pattern | Module Loading | Event Loop Blocking | Startup Delay | Verdict |
|---|---|---|---|---|
| CommonJS require with sync operations | Synchronous | Blocks event loop | High delay | [X] Bad |
| ES modules with async operations | Asynchronous | Non-blocking | Low delay | [OK] Good |