Perform various fs operations atomically in Node.js