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 🙏

© 2026 – Pkg Stats / Ryan Hefner

http-ok

v1.0.4

Published

A simple promise based http client which rejects the promise when the status ode is not 200 - OK

Readme

http-ok

npm version build status coverage status

A simple promise based http client which rejects the promise when the status is not 200 - OK

Motivation

Instead of having if-statements to check the http status code when a request returns, http-ok rejects the promise when the status code is not as expected (by default 200). This should make the promise chain look much simpler and more focused on the succes flow.

Example using 'http-ok':

const HttpOk = require("http-ok")
const client = new HttpOk(); 

client.get('www.google.com')
  .then(response => {
    /// process here the response
  })
  .catch(error => {
    /// error handling here
  }
});

Example using a http-client like 'node-fetch':

const fetch = require("node-fetch");

fetch('www.google.com')
  .then(response => {
      if(response.statusCode === 200) {
        /// process here the response
      } else {
        // error handling here
      }
    }
  ).catch(err => {
  	// error handling here
  });

Features

  • More natural promise chain by rejecting the promise when the response code is not OK
  • Stay consistent with node http API. Uses the same request options object.
  • Use native promise.

Difference from node-fetch

Install

npm install http-ok --save

Usage

plain text or html

const HttpOk = require('http-ok');
const client = new HttpOk();

client.get('https://github.com/')
	.then(res => res.text())
	.then(bodyText => console.log(bodyText))
	.catch(err => console.log(err));

json response

client.get('https://api.github.com/users/github')
	.then(res => res.json())
	.then(json => console.log(json))
	.catch(err => console.log(err));

post with form data and custom headers

const querystring = require('querystring');
const formData = { 
    name: 'Bob Mc Bobson', 
    place: 'Cheddar' 
};
const postData = querystring.stringify(formData);

const requestOptions = {
    hostname: 'http://httpbin.org',
    headers: {
         'Content-Type': 'application/x-www-form-urlencoded',
         'Content-Length': Buffer.byteLength(postData)
    }
};

client.post(requestOptions, postData, 200)
	.then(res => {
		// process here the response
	}).catch(json => {
		// error handling here
	});

specific success case eg. 302

client.get('http://redirected.com', 302)
     .then(response => {
         // process here the response
     }).catch(error => {
         // error handling here
     });

See test cases for more examples.

API

  • get(url) // default 200

  • get(url, expectedStatusCode)

  • get(options, expectedStatusCode)

  • post(url, postData) // default 200

  • post(url, postData, expectedStatusCode)

  • post(options, postData, expectedStatusCode)

Returns a Promise

url

Should be an absolute url, eg http://example.com

options

same as node.js http.request options.

expectedStatusCode

and integer eg 200 or 301

postData

url encoded string

License

MIT