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

neat-http

v0.0.10

Published

Light-weight Client Promise wrap for raw http.request

Downloads

4

Readme

neat-request

Light-weight Promise wrap for raw http.request

Install

npm install neat-http

Hello neat_http

// Now is mostly used for proxy
const request = require('neat-http');

const server = http.createServer(async function(sreq, sres) {
  const url_parts = url.parse(sreq.url);
  const opts = {
    host: 'google.com',
    port: 80,
    path: url_parts.pathname,
    method: sreq.method,
    headers: sreq.headers
  };
  const ext = {
    req: sreq, // pipe client request to server
    // timeout(Num): If None, Default is 15sec
    // toJSON(bool): Default is False.
  };
  const cres = await request(opts, ext);
  sres.writeHead(cres.statusCode, cres.headers);
  cres.pipe(sres); // pipe client to server response
});
server.listen(80, '0.0.0.0');

LBClient

const neat_http = require('../index.js');

const arr = [{
    host: 'www.upstream1.com',
    port: 8080
  },
  {
    host: 'www.upstream2.com',
    port: 8080
  },
];

const client = new neat_http.LBClient({
  path: '/path'
}, {
  rr: arr,
  timeout: 5000,
  healthCheckOpts: {
    path: '/check',
  },
  healthCheckFn: cres => cres.statusCode == 200,
  healthCheckCycle: 3000, //ms, every cycle will check all hosts
});

(async() => {
  const res = await client.send({
    path: '/test/client'
    });
})()

API

neat_http(request[opts [,ext]])

  • opts (obj) - Default is {}, the same as raw http.request(options)'s parameter.
  • ext (obj) - Default is {}, is extension object.
  • ext.req (http.ClientRequest): raw http.ClientRequest instance, used for request pipe.
  • ext.timeout (num): timeout in ms, Default is 15 second, if upstream not response, reject error.
  • ext.toJSON (bool): Default is false, if set true, will return an Object parsed from response.
  • ext.toText (bool): Default is false, if set true, will return an String parsed from response.

Class: neat_http.LBClient

new LBClient(opts [,ext])

  • ext.rr (Array) - : Default is undefined.Every element of arr will merge into options, in a round-robin manner. especially when need Load-Balance. (If rr's element have same key with options, it will not merge into, please put common key in options, dynamic for Load-Banlance put in rr )
  • ext.healthCheckOpts (obj): Default is {}, use from healCheck request options.
  • ext.healthCheckFn (fn): Default when healthCheck's response's statusCode is 200, will recieve one parameter is raw http.ServerResponse instance(healthCheck's response).
  • ext.healthCheckCycle (num): Default is 5000(ms), one cycle will check all upstreams in rr.
  • ext.timeout (num) - Defalut is 15s, timeout(ms) between proxy request send and recieve response.

client.send(opts)

The same as default neat-http(request).

Class: neat_http.HostClient

Class: neat_http.createRequest