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

@kylerross/test-server

v1.0.0

Published

A simple Koa server to respond to any URL and provide the results

Downloads

4

Readme

Test Server

A simple Koa server to respond to any URL and provide the results. Useful for debugging or testing webhook-style responses locally. This is a development server which is not made to run in production.

Install

The package comes with a command line interface as well as a programmatic interface.

CLI

npm install -g @kylerross/test-server

API

npm install --save @kylerross/test-server

CLI Usage

To start the server, run the following command:

test-server

Options

-p NUM, --port=NUM
    Port number to bind the server to.

--disable-log
    Disables logging request information to the console.

--disable-body
    Disables responding to requests with data in the response body.

-b TEXT, --custom-body=TEXT
    When the body is enabled, override the default sent JSON with the provided text.

--body-fields=LIST
    Comma-seperated list of fields to include in the response body.
    Defaults to: url, method, body, query, headers, response, app

--log-fields=LIST
    Comma-seperated list of fields to include in the log message in the console.
    Defaults to: body, query, headers

--no-colors
    Disables colors in the console-logged message.

-v, --version
    Display the CLI version and exit.

-h, --help
    Display help and exit.

API Documentation

To use the programmatic API:

const testServer = require('@kylerross/test-server');

// Start the server with or without options
testServer({
    //... options
});

Options

The following options are available to be passed into testServer().

| Option | Type | Description | Default | |---------------|---------------------|----------------------------------------------------------------------------------|--------------------------------------------------------------------| | port | Number | The port to bind the server to. | 8000 | | ignorePaths | Array<Regexp> | Path regexps to ignore requests to. | [/favicon/i, /robots\.txt/i] | | enableLogging | Boolean | Enables logging request data to the console. | true | | enableBody | Boolean | Enables returning request data in the response as JSON or value of customBody. | true | | customBody | String | Return the provided text as the body instead of the request data JSON. | null | | colors | Boolean | Enables colors when logging to the console. | true | | bodyFields | Array<String> | List of fields to display in the response body. | ['url', 'method', 'body', 'query', 'headers', 'response', 'app'] | | logFields | Array<String> | List of fields to display in the log to console. | ['body', 'query', 'headers'] | | parserTypes | Array<String> | List of parser types to allow for bodyparser. Defaults to all. | ['json', 'form', 'text'] | | jsonLimit | String | The size limit for parsing JSON bodies. | 1mb | | textLimit | String | The size limit for parsing Text bodies. | 1mb | | formLimit | String | The size limit for parsing Form bodies. | 56kb | | strictJSON | Boolean | Strict JSON mode accepts arrays and objects only. | true |

Allowed Fields

The following are the available fields that can be passed into bodyFields and logFields:

  • url - The incoming url path (ex. ctx.originalUrl)
  • method - The request method (ex. ctx.method)
  • body - The parsed incoming body from koa-bodyparser (ex. ctx.request.body)
  • query - The parsed query string from koa-qs (ex. ctx.query)
  • headers - Incoming headers object (ex. ctx.request.headers)
  • response - The response object from Node (ex. ctx.response)
  • app - The app object from Koa (ex. ctx.app)

License

MIT