show promise usage
This commit is contained in:
parent
335dd98631
commit
be91c1b78f
15
README.md
15
README.md
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue