Created
November 10, 2017 21:01
-
-
Save Bizunow/2dd71f3f3c5bff77bebd8c937e3f6c66 to your computer and use it in GitHub Desktop.
[NodeJS File Module] NodeJS file read/write async #js #nodejs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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