Skip to content

Instantly share code, notes, and snippets.

@sergiodxa
Last active August 29, 2015 14:22
Show Gist options
  • Save sergiodxa/0fc24982419588217865 to your computer and use it in GitHub Desktop.
Save sergiodxa/0fc24982419588217865 to your computer and use it in GitHub Desktop.
Creando una promesa
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