Skip to content

Instantly share code, notes, and snippets.

@Bizunow
Created November 10, 2017 21:01
Show Gist options
  • Save Bizunow/2dd71f3f3c5bff77bebd8c937e3f6c66 to your computer and use it in GitHub Desktop.
Save Bizunow/2dd71f3f3c5bff77bebd8c937e3f6c66 to your computer and use it in GitHub Desktop.
[NodeJS File Module] NodeJS file read/write async #js #nodejs
// Usage:
// await Files.write('test.json', JSON.stringify(data));
const fs = require('fs');
class Files {
static write(fname, data) {
return new Promise((resolve, reject) => {
fs.writeFile(`./${fname}`, data, (err) => {
if (err) {
console.log(err);
return reject(false);
}
resolve(true);
});
});
}
}
module.exports = Files;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment