Skip to content

Instantly share code, notes, and snippets.

@ronaldronson
Created October 23, 2018 12:15
Show Gist options
  • Save ronaldronson/08b2f058553c94e8054e10b7dab8460d to your computer and use it in GitHub Desktop.
Save ronaldronson/08b2f058553c94e8054e10b7dab8460d to your computer and use it in GitHub Desktop.
Node request with promises.
const http = require('http')
function makeCall(options) {
return new Promise(function(resolve, reject) {
const req = http.request(options, (res) => {
const q = []
res.setEncoding('utf8')
res.on('data', (chunk) => q.push(chunk))
res.on('end', () => resolve(q.join('')))
})
req.on('error', (e) => reject(e))
req.write('') // pass requrst body here
req.end()
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment