Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including superagent-as-promised with all npm packages installed. Try it out:

var superagentAsPromised = require("superagent-as-promised")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

superagent-as-promised v4.0.0

SuperAgent with a Promise twist

SuperAgent as Promise(d)

SuperAgent as Promise

Installation

npm install superagent-as-promised

Usage

var request = require('superagent');
require('superagent-as-promised')(request);

Then

request
.get('/location')
.then( function(response) {
  console.log("Got "+response.text);
})
.catch( function(error) {
  console.dir(error);
})

is syntactic sugar for:

var promise = request
  .get('/location')
  .endAsync();

promise
  .then( function(response) {
    console.log("Got "+response.text);
  })
  .catch( function(error) {
    console.dir(error);
  })

Options

require('superagent-as-promised')(SuperAgent,Promise);

SuperAgent must be a SuperAgent class; it is extended with endAsync(), then, and catch methods. The optional Promise parameter allows you to provide your own Promise class; bluebird is used by default.

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free