Performance: Appending to files
This affects how fast data is written to disk and how the Node.js event loop handles file I/O operations.
Jump into concepts and practice - no test required
import { appendFile } from 'fs/promises'; const data = 'New log entry\n'; await appendFile('log.txt', data);
const fs = require('fs'); const data = 'New log entry\n'; fs.appendFileSync('log.txt', data);
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Synchronous appendFileSync | N/A | N/A | N/A | [X] Bad |
| Asynchronous appendFile (Promise) | N/A | N/A | N/A | [OK] Good |
import { appendFile } from 'fs/promises';
await appendFile('log.txt', 'Entry1\n');
await appendFile('log.txt', 'Entry2');import fs from 'fs/promises';
fs.appendFile('data.txt', 'New line');
console.log('Appended');