npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

preq

v0.5.14

Published

Yet another promising request wrapper

Downloads

5,749

Readme

preq Build Status

Yet another promising request wrapper.

Features

  • ES6 Promise-based, using the excellent bluebird by default
  • Robustness: retry, timeout and connect timeout support
  • Proper error handling: All errors (incl. HTTP responses with code >= 400) throw exceptions, and can be caught with Promise.catch(). This ensures that all errors are handled, and often cleans up the code by clearly separating out error handling. The HTTPError instance has all the properties of a normal response.

Installation

npm install preq

Usage

var preq = require('preq');

return preq.get({                   // or preq.request({ method: 'get', .. })
    uri: 'http://google.com/',
    headers: {
        'x-foo': 'bar'
    },
    query: {
        q: 'foo'
    },
    // body for POSTs or PUTs, can be object (serialized to JSON), Buffer or String
})
.then(function(res) {
    /**
     * { 
     *   status: 200,
     *   headers: { 
     *     date: 'Sat, 21 Feb 2015 01:47:40 GMT' // , ...
     *   },
     *   body: '<!doctype html>...</html>' // or object if json
     * }
     */
})
.catch(function(err) {
    // Any response with HTTP status >= 400
    // err is HTTPError with same properties as response above
});

preq-specific parameters / methods

preq passes through most options directly to request, so see its documentation for advanced options.

Additionally, it defines or modifies these request options:

  • method: Lowercase HTTP verbs. Automatically set by the verb methods (preq.get(), .post() etc).
  • uri: use uri, not url.
  • query: query string parameters
  • body: String, Buffer or Object. If an object is supplied, the serialization depends on the content-type header. Supported:
    • application/json.*
    • multipart/form-data
    • application/x-www-form-urlencoded
  • retries: Maximum number of retries. Exponential back-off is used between retries.
  • timeout: Total request timeout.

The connection timeout, maximum time to establish a TCP connection to the host is 5 seconds by default and can be altered with PREQ_CONNECT_TIMEOUT environment variable.

Also see the tests for usage examples.