http-as-promised

raw JSON →
2.0.1 verified Sat Apr 25 auth: no javascript deprecated

A Node.js HTTP client that wraps the request library with Bluebird promises, automatically rejecting on HTTP error status codes (>= 400). Version 2.0.1 is the latest stable release (last updated 2016). The package is deprecated in favor of using modern HTTP clients like `node-fetch` or `axios` with native promises. Key differentiators: built-in HTTP error classes for specific status codes (e.g., `NotFoundError`, `InternalServerError`) and automatic rejection on non-2xx responses.

error Error: Cannot find module 'http-as-promised'
cause Package not installed or used with ESM import
fix
Run npm install http-as-promised and use require('http-as-promised')
error TypeError: $http(...).then is not a function
cause Forgetting to call $http as a function
fix
Ensure you call $http() and not use it as a static object
error Unhandled rejection: HTTPError: Not Found
cause Request returned 404 and no catch handler
fix
Add .catch() or use try/catch with async/await
deprecated Package is deprecated
fix Use axios, node-fetch, or got instead
breaking Requires Node >=4 (no longer maintained for modern versions)
fix Update to Node >=10 or use alternative HTTP client
gotcha Promise resolves with array [response, body] by default, not just body
fix Use .spread() or set resolve option to 'body' if you only want the body
gotcha Automatically rejects for status codes >=400 unless error option is false
fix Set error: false in options to handle 4xx/5xx responses yourself
deprecated Request library is deprecated
fix Use a different HTTP client
npm install http-as-promised
yarn add http-as-promised
pnpm add http-as-promised

Shows basic GET request with spread to access response and body, and catch for HTTP errors.

var $http = require('http-as-promised');

$http('https://api.github.com', { headers: { 'User-Agent': 'http-as-promised' } })
  .spread(function (response, body) {
    console.log('Status:', response.statusCode);
    console.log('Body:', body);
  })
  .catch(function (err) {
    console.error('Request failed:', err.message);
  });