Last active
August 29, 2015 14:22
-
-
Save sergiodxa/0fc24982419588217865 to your computer and use it in GitHub Desktop.
Creando una promesa
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
import fs from 'fs'; | |
function readFile (fileName) { | |
return new Promise((resolve, reject) => { | |
fs.readFile(fileName, (error, data) => { | |
if (error) reject(error); | |
else resolve(data); | |
}); | |
}); | |
} | |
readFile('archivo.txt') | |
.then(data => console.log(data.toString())) | |
.catch(error => console.error(error)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment