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

servson

v0.1.3

Published

Mock REST API via JSON file

Downloads

4,484

Readme

servson

npm version license

Complete REST Mock API in seconds using just a single JSON file. Create mocks for your front-end in seconds.


How to use

Run the init command to generate the default configuration file mock.json:

npx servson init

Start the Server

Pass the configuration file you want to use to servson:

npx servson mock.json

The REST Mock API server will start on the port defined in settings.port.


Configuration file (mock.json)

The configuration file defines your mock data models.

{
    "$schema": "https://unpkg.com/servson@latest/static/schema.json",
    "settings": {
        "host": "localhost",
        "port": 3000,
        "identity": {
            "type": "number",
            "field": "id"
        },
        "timestamps": {
            "createdAt": true,
            "updatedAt": true
        },
        "pagination": {
            "limit": 10
        },
        "responses": {
            "get": { "status": 200 },
            "post": { "status": 201 },
            "put": { "status": 200 },
            "delete": { "status": 204 },
            "errors": {
                "modelNotFound": {
                    "status": 404,
                    "message": "Model '{{model}}' not found"
                },
                "notFound": {
                    "status": 404,
                    "message": "Item not found"
                },
                "duplicate": {
                    "status": 400,
                    "message": "Item already exists"
                }
            }
        }
    },
    "models": [
        {
            "name": "user",
            "data": [
                {
                    "name": "John Doe",
                    "email": "[email protected]"
                }
            ]
        }
    ]
}

REST Endpoints

For each model defined in models, servson automatically exposes the following RESTful routes:

GET          /              Lists status and available routes   200
GET          /:model        Lists all records                   200
GET          /:model/:id    Finds a record by ID                200 / 404
POST         /:model        Creates a new record                201 / 400
PUT          /:model/:id    Updates a record by ID              200 / 404
DELETE       /:model/:id    Removes a record by ID              204 / 404

Query Parameters (Pagination & Sorting)

The GET /:model endpoint supports pagination and sorting via query parameters:

GET /user?page=2               # Page number to fetch (default: 1)
GET /user?limit=5              # Max items returned in data (default: 10 or settings.pagination.limit)
GET /user?sort=name            # Sort by field ascending
GET /user?sort=-views          # Sort by field descending (prefix with -)
GET /user?page=2&limit=5&sort=name # Combine page, limit, and sorting

Paginated Response Format

{
    "first": 1,
    "prev": null,
    "next": 2,
    "last": 5,
    "pages": 5,
    "items": 25,
    "data": [
        {
            "id": 1,
            "name": "John Doe",
            "email": "[email protected]"
        }
    ]
}

CLI Commands

Usage: servson [options] [command] [config]

Mock REST API via JSON file

Arguments:
  config               JSON configuration file

Options:
  -v, --version        Display version
  -c, --config <path>  Configuration file path
  -h, --help           Display help

Commands:
  init [options]       Generate mock.json file

init command options

servson init [options]
  • -f, --force: Overwrite without asking.

License

MIT