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 🙏

© 2025 – Pkg Stats / Ryan Hefner

x-requests

v1.0.0

Published

[Build Status](https://travis-ci.org/x-component/x-request.png?v1.0.0)](https://travis-ci.org/x-component/x-request)

Downloads

5

Readme

x-request

Build Status](https://travis-ci.org/x-component/x-request)

./request.js

request

x-request

This is a wrapper around the request module to create preconfigured backend clients

  • configurable backend parameters:
-- configuration of a target url prefix
-- configurable headers with a generated request id
-- configurable retry
  • logging

Example for a backend client

 'use strict';
 var
    config  = require('x-configs')(__dirname+'/config'),
    request = require('x-request');
 module.exports = request(config);
 module.exports.config = config;
 request.client(config,__filename);

Where __dirname+'/config.js is :

 'use strict';
 var merge=require('x-common').merge;
 var generic={
     // name added to log entries for each requests
     name: 'MYSERVER',
     // optional pre configured backend url prefix with protocol server, port and path prefix
     url:'http://myserver:28080/prefix',
     // optional example fora get used in usage of the command line client
     example: '/',
     // optional name of header wich will contain a automatic generated request id,
     // this allows to correlate a log entry here with a log entry in the backend.
     id_header: 'x-reqid',
     // optionally define known options for the request module
     request: {
         timeout           : 65000,
         maxSockets        : 128,
         followRedirect    : false,
         followAllRedirects: false,
         jar               : false,
         json              : true,
         headers           : {
             'x-reqid':'' //is automatically set
             'x-powered-by : 'x-x.io'
         }
     },
     retry : {
         // options as defined by node module retry: formula used var Math.min(random * minTimeout * Math.pow(factor, attempt), maxTimeout);
         retries    : 0,    // The maximum amount of times to retry the operation. Default is 10.
         factor     : 2,    // The exponential factor to use. Default is 2
         minTimeout : 300,  // The amount of time before starting the first retry. Default is 1000.
 12         maxTimeout : 6000, // The maximum amount of time between two retries. Default is Infinity.
 13         randomize  : true, // Randomizes the timeouts by multiplying with a factor between 1 to 2. Default is false.
 14         test       : function( err, mce_res, body ){ return err || (mce_res && 429 === mce_res.statusCode); }
 15     }
 };

Using such a client:

  request = require('myserver');
  // example: create a item by calling POST http://myserver:28080/prefix/items, with a callback next
  function create(next){
      request.post({url:'/items',json:{name:'abc'}},function(err, backend_response, backend_json){
        next && next( err || backend_response.error() || void 0, json );
      });
  };

You can check the backend_response statuscodes with

  if( backend_response.success()     ){...} //  200 <= statusCode <= 299
  if( backend_response.redirect()    ){...} //  300 <= statusCode <= 399
  if( backend_response.error()       ){...} //  400 <= statusCode
  if( backend_response.error.client()){...} //  400 <= statusCode <= 499
  if( backend_response.error.server()){...} //  500 <= statusCode <= 599

name : 'MCE Topup',

  7     url   : 'http://localhost:48080/mce-mock',
  8     retry : { // as defined by node module retry: formula used var Math.min(random * minTimeout * Math.pow(factor, attempt), maxTimeout);
  9         retries    : 0,    // The maximum amount of times to retry the operation. Default is 10.
 10         factor     : 2,    // The exponential factor to use. Default is 2
 11         minTimeout : 300,  // The amount of time before starting the first retry. Default is 1000.
 12         maxTimeout : 6000, // The maximum amount of time between two retries. Default is Infinity.
 13         randomize  : true, // Randomizes the timeouts by multiplying with a factor between 1 to 2. Default is false.
 14         test       : function( err, mce_res, body ){ return err || (mce_res && 429 === mce_res.statusCode); }
 15     }

module.exports={ development : merge({},generic,{ url:'http://mucprxwap01:28080' // note via varnish in front of node }),

test : merge({},generic,{
}),

production : merge({},generic,{
})

};