Skip to content

Instantly share code, notes, and snippets.

@zacharyhill
Created January 19, 2018 04:03
Show Gist options
  • Save zacharyhill/bee7b19490ff3879ba1f80f6985f3748 to your computer and use it in GitHub Desktop.
Save zacharyhill/bee7b19490ff3879ba1f80f6985f3748 to your computer and use it in GitHub Desktop.
const fs = require('fs');
module.exports.getFiles = function() {
return new Promise((resolve, reject) => {
fs.readFile('/home/usr', (err, data) => {
if (err) {
reject(err);
}
else {
resolve(data);
}
});
});
}
// then in another file we can call
const whatever = require('./filename');
whatever.getFiles
.then((data) => {
console.log(data);
})
.catch((err) => {
console.log(err);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment