show promise usage

This commit is contained in:
AJ ONeal 2019-06-04 04:19:11 +00:00
parent 335dd98631
commit be91c1b78f
1 changed files with 15 additions and 0 deletions

View File

@ -23,6 +23,21 @@ request('http://www.google.com', function (error, response, body) {
}); });
``` ```
**Using Promises**
```js
var promisify = require('util').promisify;
var request = require('@root/request');
request = promisify(request);
request('http://www.google.com').then(function (response) {
console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
console.log('body:', response.body); // Print the HTML for the Google homepage.
}).catch(function (error) {
console.log('error:', error); // Print the error if one occurred
});
```
## Table of contents ## Table of contents
- [Forms](#forms) - [Forms](#forms)