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

dev-api-server

v1.2.0

Published

Configurable API server for client development

Readme

dev-api-server

Configurable api server (only) for client development

DO NOT USE THIS FOR ANY KINDS OF PRODUCTION LEVEL DEPLOYMENTS

How to Install

  1. To install globally, run following command at any directory.
    npm i -g dev-api-server
  2. To install locally, run following command in your project.
    npm i -D dev-api-server

How to Use

Let's suppose that you have dev-api.json in your current directory with following contents (You can find the file in examples/dev-api.json)

{
  "apis": [
    {
      "apiPath": "/",
      "body": "Hello dev-api-server!"
    },
    {
      "apiPath": "/file",
      "filePath": "dev-api.json"
    }
  ]
}

To execute dev-api-server,

  1. When you installed it globally,
    dev-api-server
  2. When you installed it locally,
    npx dev-api-server

Now let's open the browser (or any other REST client tools) and access localhost:3210/ and localhost:3210/file!

You can also use custom config file. This time, let's suppose that you have my-api.json in your current directory with following contents (Again, you can find the file in examples/my-api.json)

{
  "apis": [
    {
      "apiPath": "/dev",
      "body": "hello"
    },
    {
      "apiPath": "/(.*)",
      "code": 503
    }
  ]
}

You can run dev-api-server with

  1. When you installed it globally,
    dev-api-server ./my-api.json
  2. When you installed it locally,
    npx dev-api-server ./my-api.json

Now when you access localhost:3210/dev, and any other paths will give you HTTP 503 error.

DIY Configurations

To make your own configuration, you can use following keys.

apis

The value of "apis" should be an array of apis.

api

api is one of following type with common keys like "apiPath", "headers".

  1. Body API
  2. Serving API
  3. Failing API

api.apiPath [REQUIRED]

"apiPath" is a path for the api. You can use any string that works with path-to-regexp.

api.headers

The value of "headers" is an optional object whose keys are header names and values are header values. For example, with following json,

{
  "apis": [
    {
      "apiPath": "/",
      "headers": {
        "Content-Type": "application/json"
      },
      "body": "{ \"abc\": \"def\" }"
    }
  ]
}

when you access / path it will give you json-parsed "{ \"abc\": \"def\" }".

Body API

Body API is an api with "body" (REQUIRED) whose value is string or object. However, if you want to get the object as JSON format, you should add "Content-Type" header just like what we did in headers section.

Serving API

Serving API is an api with "filePath" (REQUIRED) whose value is string. This API sends a file in the "filePath". When you use relative path for "filePath", it will resolved from the directory where you execute dev-api-server. "filePath" also accepts path-to-regexp parameters. For example,

{
  "apis": [
    {
      "apiPath": "/file/:file",
      "filePath": "./serving/:file"
    }
  ]
}

will serve ./serving/abc.html for path /file/abc.html, and serve ./serving/world/is.js for path /file/world/is.js.

You can try examples/path-to-regexp.json in examples directory with paths like /dev-api.json and /my-api.json

Failing API

Failing API is an api with "code" (REQUIRED) whose value is number. This API always sends that code as a HTTP status code.

port

You can change your port by setting "port". For example,

{
  "port": 5040
}

will give you a server with 5040 port.

host

You can change your host by setting "host".

Options

You can also have few options.

--help

Surprise surprise... With this option, app displays help message.

--watch

When you run dev-api-server with this option, dev-api-server will be restarted whenever your config json file is updated.

--version

Oh, one more creative option! App will give you a version of dev-api-server!

Author