From be91c1b78f056292d2a7eea9e67e5ff390f8ef91 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Tue, 4 Jun 2019 04:19:11 +0000 Subject: [PATCH] show promise usage --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index 222ad3f..9dbeac4 100644 --- a/README.md +++ b/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 - [Forms](#forms)