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

algo-httpserv

v1.2.1

Published

Dead simple, unbloated HTTP(s) request handler, perfect for the programmer with better things to do.

Downloads

352

Readme

httpserv

Dead simple, unbloated HTTP(s) request handler, perfect for the programmer with better things to do.

How do I use httpserv?

  • Create an http or https server using default Node.JS libs.
  • Import httpserv
  • Use httpserv.serve as the server request handler
const http = require("http"); // Or you could use HTTPS
const httpserv = require("httpserv"); // or "./httpserv" if you downloaded the source
const server = http.createServer(httpserv.serve);
server.listen(serverOptions.port);

Where do I put my html files?

  • Create a directory called "serve", wherever your main server file is
  • That's where

Note: other file extentions are available

What about handling POST and GET requests and all that jazz?

  • Sure. Here's one that handles any method of request:
httpserv.on("/api_endpoint/", (request, response, url) => {
    response.writeHead(200, {"Content-Type": "application/json"});
    response.write(JSON.stringify(url.query));
    response.end();
});
  • Here's one that handles only GET requests:
httpserv.on("/api_endpoint/", "GET", (request, response, url) => {
    response.writeHead(200, {"Content-Type": "application/json"});
    response.write(JSON.stringify(url.query));
    response.end();
});
  • Here's one that handles both GET and POST requests:
httpserv.on("/api_endpoint/", ["GET", "POST"], (request, response, url) => {
    response.writeHead(200, {"Content-Type": "application/json"});
    response.write(JSON.stringify(url.query));
    response.end();
});
  • New and super exciting in version 1.2: Match with regex!

Note: I am bad at regex

httpserv.on(/\/regex-endpoint\/*/, ["GET", "POST"], (request, response, url) => {
    response.writeHead(200, {"Content-Type": "application/json"});
    response.write("Regex requirement met!");
    response.end();
});

For the curious minds, the third parameter ("url") is just the result of url.parse(request.url, true), which is convenient to have when handling your own requests. "request" and "response" are directly from the server

Screw relative paths, amirite?

New in version 1.2: kick them to the curb!

use the function setServePath and the variable __dirname to make your script run from anywhere on the drive. Take a look!

httpserv.setServePath(__dirname + "/serve");

Run it from anywhere! Here I am one directory up.

Relative paths are for losers

Or don't do that!

  • If that's too much work for you, httpserv still runs off relative paths by default. Which is ok enough I guess

Does it support HTTPS?

  • httpserv doesn't care

If you have been paying attention, you will have noticed that httpserv doesn't actually create a server for you, it handles the requests an already existing server might get. Therefore, you can create either an HTTP or HTTPS server, and httpserv will hardly notice the difference.

Notes

  • Any request omitting an .html extention will be treated as an HTML request, if the exact file does not exist
  • MIME types (Content-Type) are determined based on the extention from the request. There is a small database included in the library with common items. If you need to modify them, just do it in the source code. They're right near the top. Of course, this behavior is ignored with custom handlers.
  • File serving is stream-based
  • Files do not cache (Although, I have interest in implementing this)
  • No dependencies
  • Streaming audio and video should be okay, but it is untested