Node.js · File System · Junior · Live Coding
How do you safely write a file atomically?
Short Interview Answer
Write to a temp file in the same directory, then rename (fs.rename) over the target.
Detailed Explanation
Rename is atomic on same filesystem. Avoid partial reads of half-written configs. fsync when durability requires it.