Created
October 4, 2017 10:30
-
-
Save avermeulen/be6c6820ebf876c2a214963196273097 to your computer and use it in GitHub Desktop.
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
const fs = require('fs'); | |
const {promisify} = require('util'); | |
// Using Node 8.x to create a promise for us | |
let asyncReadFile = promisify(fs.readFile); | |
/** | |
Create your own Promise | |
**/ | |
function readFile(fileName){ | |
return new Promise(function(accept, reject){ | |
fs.readFile(fileName, "utf-8", function(err, result){ | |
if(err){ | |
return reject(err); | |
} | |
return accept(result); | |
}) | |
}); | |
} | |
(async () => { | |
let result = await readFile("cale.txt"); //asyncReadFile("cale.txt", "utf-8") | |
console.log(result); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment