Skip to content

Instantly share code, notes, and snippets.

@rikkrome
Created May 13, 2021 22:11
Show Gist options
  • Save rikkrome/18e681440b1656528db968ac9f5c4a5e to your computer and use it in GitHub Desktop.
Save rikkrome/18e681440b1656528db968ac9f5c4a5e to your computer and use it in GitHub Desktop.
writeToFile nodejs
const fs = require("fs");
const writeToFile = (file, data) =>
new Promise((resolve, reject) => {
try {
if (file) {
fs.writeFile(file, data, err => {
if (err) {
console.log("writeFile error: ", err);
resolve({ error: true })
}
resolve({ error: false })
});
}
} catch (error) {
console.log("writeToFile error", error);
resolve({ error: true })
}
})
module.exports = writeToFile;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment