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

cli-mockserver

v1.2.0

Published

create mock server on the go from ui or json schema

Readme

🚀 MockServer

A powerful CLI tool to spin up mock servers instantly with built-in chaos engineering capabilities. Perfect for frontend development when backend APIs aren't ready yet.

✨ Features

  • 🎯 Quick Setup - Initialize and start mock servers in seconds
  • 📱 Ready-Made Templates - Social media, e-commerce, and basic templates
  • 🔥 Chaos Engineering - Test error handling with configurable failure rates
  • 📊 Pagination Support - Automatic pagination for large datasets
  • 🎨 Pretty Logging - Beautiful, colorful CLI output
  • Hot Reload - Watch mode for schema changes
  • 🌐 Full REST Support - GET, POST, PUT, PATCH, DELETE methods
  • 📝 Rich Data Types - 20+ field types powered by Faker.js

📦 Installation

npm install -g cli-mockserver

Or use locally in your project:

npm install --save-dev cli-mockserver

🚀 Quick Start

1. Initialize a new schema

mockserver init

Choose from templates:

  • 📱 Social Media (posts, comments, users, likes, etc.)
  • 🛒 E-commerce (products, orders, cart)
  • 📝 Basic (simple REST endpoints)

2. Start the server

mockserver start

Your mock API is now running at http://localhost:9500!

3. Test your endpoints

curl http://localhost:9500/api/users
curl http://localhost:9500/api/posts
curl http://localhost:9500/api/posts/123/comments

📖 Commands

start - Start the mock server

mockserver start [options]

Options:
  -p, --port <port>        Override port from schema
  -h, --host <host>        Host address (default: localhost)
  --no-chaos               Disable chaos engineering
  -w, --watch              Watch schema file for changes

init - Initialize a new schema

mockserver init [options]

Options:
  -t, --template <name>    Use template (social, ecommerce, basic)
  -f, --force              Overwrite existing schema

validate - Validate schema.json

mockserver validate [options]

Options:
  -s, --schema <path>      Path to schema file

info - Show schema information

mockserver info

generate - Generate static JSON files

mockserver generate [options]

Options:
  -o, --output <dir>       Output directory (default: ./mock-data)

🎨 Field Types

MockChaos supports 20+ field types:

Basic Types

  • uuid - Unique identifier
  • email - Email address
  • username - Username
  • firstName - First name
  • lastName - Last name
  • sentence - Random sentence
  • paragraph - Random paragraph
  • word - Random word
  • avatar - Avatar image URL
  • image - Random image URL
  • url - Random URL
  • city - City name
  • timezone - Timezone string
  • boolean - true/false

Date Types

  • date:past - Past date
  • date:recent - Recent date (last few days)
  • date:future - Future date
  • date:recent:nullable - Recent date or null

Advanced Types

  • integer:min:max - Integer in range (e.g., integer:0:100)
  • enum:a,b,c - Random from list (e.g., enum:admin,user,guest)
  • array:type:min:max - Array of items (e.g., array:image:0:5)
  • image:type - Typed image (e.g., image:landscape, image:portrait)

Nested Objects

{
  "fields": {
    "user": {
      "id": "uuid",
      "name": "firstName",
      "email": "email"
    }
  }
}

🔥 Chaos Engineering

Enable chaos mode to test error handling:

{
  "chaos": {
    "enabled": true,
    "globalErrorRate": 0.05,
    "scenarios": {
      "timeout": 0.02,
      "serverError": 0.03,
      "networkError": 0.02
    }
  }
}

Set resource-specific error rates:

{
  "resources": [
    {
      "endpoint": "/api/users",
      "errorConfig": {
        "rate": 0.8,
        "code": 503,
        "message": "Database Connection Failed"
      }
    }
  ]
}

📊 Pagination

Enable pagination for large datasets:

{
  "resources": [
    {
      "endpoint": "/api/posts",
      "count": 100,
      "pagination": {
        "enabled": true,
        "pageSize": 15
      }
    }
  ]
}

Query with pagination:

curl http://localhost:9500/api/posts?page=2&limit=10

Response includes pagination metadata:

{
  "data": [...],
  "pagination": {
    "page": 2,
    "limit": 10,
    "total": 100,
    "totalPages": 10,
    "hasNext": true,
    "hasPrev": true
  }
}

🎯 Example Schema

Here's a complete social media schema:

{
  "port": 9500,
  "host": "localhost",
  "chaos": {
    "enabled": true,
    "globalErrorRate": 0.05
  },
  "resources": [
    {
      "id": "users",
      "name": "Users",
      "endpoint": "/api/users",
      "method": "GET",
      "count": 50,
      "pagination": {
        "enabled": true,
        "pageSize": 20
      },
      "fields": {
        "id": "uuid",
        "username": "username",
        "email": "email",
        "avatar": "avatar",
        "verified": "boolean",
        "followersCount": "integer:0:10000",
        "bio": "sentence",
        "createdAt": "date:past"
      }
    }
  ]
}

🛠️ Development

# Clone the repository
git clone https://github.com/himasnhu-at/mockserver.git
cd mockserver

# Install dependencies
npm install

# Build
npm run build

# Development mode
npm run dev start

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

📄 License

BSD-3-Clause License - feel free to use this in your projects!

🙏 Acknowledgments


Made with ❤️ for frontend developers who are tired of waiting for backend APIs