Created
March 8, 2019 16:58
-
-
Save grekodev/67fd1ffd12c9a4d995ea3a9372c4ebe8 to your computer and use it in GitHub Desktop.
Adaptando un callback a 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
| const request = require('request'); | |
| function leer(url) { | |
| return new Promise((resolve, reject) => { | |
| request(url, function (err, response) { | |
| if (err) { | |
| reject(err) | |
| } else { | |
| resolve(response); | |
| } | |
| }) | |
| }); | |
| } | |
| leer('https://google.com') | |
| .then(response => console.log(response)) | |
| .catch(err => console.log(err)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment