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

servstub

v1.0.3

Published

a cli tool for quickly defining stateless apis

Readme

servstub

a cli tool for quickly defining stateless apis

EITHER

configure a server with the cli

user@machine$ servstub
servstub> add GET /hello {"body":"HelloWorld!"}
servstub> start

OR

configure a server with a config file

// config.js
module.exports = [
  {
    'route': '/hello',
    'method': 'get'
    'response': {
      'body': 'HelloWorld!'
    }
  },
  // ...
];

and

user@machine$ servstub config.js

AND PRESTO!

user@machine$ curl -X GET http://localhost:8000/hello
HelloWorld!

Installation

npm install -g servstub

will install servstub globally, and allow you to use the cli anywhere

Prerequisites

Usage

just run

servstub

and you will cbe prompted to add endpoints. or, if you have a config file, run

servstub path/to/configfile.js --port 4321

and an api server will spin up on port 4321. you can also write -p 4321 or --port=4321 for the same result. specifying a port is optional

Configuration

you can either configure servstub with the command line or with a file

CLI Configuration

simply running servstub will put you in the configuration tool the available commands are:

add

add a new endpoint config, specifying method, then route, then response. rules defined here apply to the values of those properties.

ex: add POST /data 201

rm

remove an existing config by method and route.

ex: rm POST /data

port

specify the port on which you wish to run the server.

ex: port 4321

info

print the endpoints you've configured.

ex: info

start

start the server.

ex: start

quit

quit.

ex: quit

File Configuration

basic rules:

  1. you must create a config file for servstub to work
  2. the config file must be a .js file with a default export
  3. the export must be of type Array, where each item represents is an endpoint_config

(example)

endpoint_config object

an endpoint_config object has the following properties:

route (string/array, required)

defines valid route(s). if route is a string, it is passed as-is into express as a route. if route is an array of strings, each string is passed a new route.

method (string/array, required)

defines valid methods. if method is a string, it is passed as-is into express as a route. if method is an array of strings, each string is passed as a new method on a route.

response (number/function/response_config, required)

defines response. the following situations apply given the type of response:

number: if response is a number, the endpoint with return that number as the status code, with an empty reponse body

response_config: if response is an object, it must conform to the response_config schema

function (ADVANCED): if response is a function, express will call that function with the Request and Response objects, as if you were defining a route manually. see this documentation for examples

response_config object

an endpoint_config object has the following properties:

"body" (string/number/object, required)

this is the body of the response

"headers" (object)

an object that will extend the existing headers. default: {}

"status" (number)

the status code to send back with the response. default: 200

example

module.exports = [
    // creates a single endpoint
    // GET /foo
    // that returns a 200 OK with body { "answer": 42 }
    {
        route: '/foo',
        method: 'get',
        response: {
            'body': {
                'answer': 42
            },
            'status': 200
        }   
    },
    // creates six endpoints
    // GET /bar, POST /bar, DELETE /bar
    // GET /baz, POST /baz, DELETE /baz
    // all will return a 403 FORBIDDEN
    {
        route: ['/bar', '/baz'],
        method: ['get', 'post', 'delete'],
        response: 403
    },
    // creates a single endpoint
    // GET /echo
    // that returns whatever you put
    // the "message" query parameter
    {
        route: '/echo',
        method: 'get',
        response: (req, res) => res.send(req.query.message)
    }
];