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

@mudit_jain/mockapi-server

v1.0.3

Published

A simple mock API server with delays , failures and dashboard UI

Readme

@mudit_jain/mockapi-server

A lightweight Node.js package to quickly mock REST APIs for development and testing. It allows you to simulate various API responses with customizable delay, failure rates, and data generation based on a schema using Faker.js.

Features

  • Dynamic Route Configuration: Define routes and behaviors with custom paths, methods (GET/POST), delay times, and failure rates.
  • Custom Error Handling: Simulate custom error responses with customizable status codes and messages.
  • Fake Data Generation: Automatically generate fake data based on provided schemas using Faker.js.
  • Logging and Dashboard: Track recent API requests with built-in logging and a simple web dashboard.
  • CLI Support: Start the mock API server using a simple command.

Installation

To install @mudit_jain/mockapi-server, use the following npm command:

npm install @mudit_jain/mockapi-server --save-dev

Usage

Starting the Mock API Server

You can start the mock API server by running:

mockapi examples/basic.mock.json

This will start the server using the routes defined in the basic.mock.json configuration file. You can modify this file to suit your needs.

Configuration Example

Create a basic.mock.json file to define the routes and behavior of your mock API. Here's an example of a configuration file:

{
  "routes": [
    {
      "method": "GET",
      "path": "/users",
      "delay": 500,
      "failRate": 0.1,
      "count": 5,
      "schema": {
        "id": "random.uuid",
        "name": "name.findName",
        "email": "internet.email"
      }
    },
    {
      "method": "POST",
      "path": "/users",
      "delay": 300,
      "failRate": 0.2
    }
  ]
}

How It Works

  1. GET Requests: Return an array of fake data based on the schema field. For example, id: "random.uuid" will generate a random UUID, name: "name.findName" will generate a random name, and email: "internet.email" will generate a random email address.

  2. POST Requests: Accept the request body and return the same payload with a 201 Created status. You can adjust failure rates for POST requests as well.

  3. Custom Errors: You can define a customError object in your configuration to simulate errors. For example:

"customError": {
  "status": 500,
  "message": "Simulated server error"
}

API Dashboard

To monitor your mock API server, visit the /__dashboard__ endpoint, where you can view the 50 most recent API requests.

http://localhost:4000/__dashboard__

CLI Command

Once installed, you can run the mock server using the CLI command:

mockapi <config_file>

This command will read the specified JSON configuration file, set up the routes, and start the server on port 4000.

Example Configuration File (basic.mock.json)

{
  "routes": [
    {
      "method": "GET",
      "path": "/users",
      "delay": 500,
      "failRate": 0.1,
      "count": 5,
      "schema": {
        "id": "random.uuid",
        "name": "name.findName",
        "email": "internet.email"
      }
    },
    {
      "method": "POST",
      "path": "/users",
      "delay": 300,
      "failRate": 0.2
    }
  ]
}

Contributing

If you'd like to contribute to this project, feel free to fork the repository, create a new branch, and submit a pull request.

License

This project is licensed under the MIT License - see the LICENSE file for details.


### Key Updates:

- **Schema**: The schema now supports using Faker functions like `random.uuid`, `name.findName`, and `internet.email` for generating fake data.
- **CLI Command**: You can run the mock API server with the `mockapi` command.
- **Dashboard**: The dashboard will show the 50 most recent API requests.