fs.writeFile in a promise, asynchronous-synchronous stuff
As of 2019… …the correct answer is to use async/await with the native fs promises module included in node. Upgrade to Node.js 10 or 11 (already supported by major cloud providers) and do this: const fs = require(‘fs’).promises; // This must run inside a function marked `async`: const file = await fs.readFile(‘filename.txt’, ‘utf8’); await fs.writeFile(‘filename.txt’, … Read more