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

mockadin

v1.2.0

Published

A CLI tool to quickly scaffold and serve mock APIs using static JSON or dynamic JavaScript handlers, with hot-reload support and CRUD operations with data persistence for rapid development.

Readme

mockadin

A simple CLI tool to quickly create and serve mock APIs for development and testing. Supports static JSON responses and dynamic JavaScript handlers, with hot-reload for instant feedback.


Index

  1. Features
  2. Installation
  3. Project Initialization
  4. Starting the Server
  5. Generating Mocks Interactively
  6. CRUD Operations with Data Persistence
  7. Usage Examples
  8. Route Mapping
  9. Links
  10. License

1. Features

  • Zero-config mock API server
  • Serve static JSON or dynamic JS handlers
  • Supports GET, POST, PUT, DELETE
  • Hot reload on file changes
  • Easy CLI commands: init, serve, generate and crud
  • Colorful logs for easy debugging
  • RESTful route mapping (no HTTP verb in the URL)
  • Swagger documentation generation
  • CRUD operations with in-memory data persistence

2. Installation

You can install and use mockadin in two ways:

a) Using npm (recommended)

Install globally:

npm install -g mockadin

Or use with npx (no global install needed):

npx mockadin init
npx mockadin serve

b) Cloning the repository

git clone https://github.com/lucasmarkes/mockadin.git
cd mockadin
npm install

3. Project Initialization

Initialize a mock project with example files:

mockadin init <project-folder-name>

or, if you omit the folder name, the CLI will prompt you for it:

mockadin init

You will see a welcome message and be asked to enter the project folder name.
The project will always be created in a new folder with the name you provide (it will not overwrite your current directory).

This creates:

mocks/
  get/
    users.json
  post/
    users.js
  put/
    users.js
  delete/
    users.js
server/
  index.mjs

4. Starting the Server

Start the mock API server:

mockadin serve

The server will run at http://localhost:4000 by default.

After starting the server, you can access the interactive API documentation at: http://localhost:4000/api-docs

You can change the port by setting the PORT environment variable:

PORT=5000 mockadin serve

5. Generating Mocks Interactively

You can generate mock endpoints for any resource using the interactive CLI:

mockadin generate [resource-name]
  • If you omit the resource name, the CLI will prompt you for it.
  • You will be asked which HTTP methods (GET, POST, PUT, DELETE) you want to generate for this resource.
  • For GET, you can define the fields, types, and how many objects to generate (using fake data).
  • For POST, PUT, and DELETE, handler files are generated that return example responses.
  • All files are created in the appropriate mocks/<method>/ folders.

Example:

mockadin generate books

This will guide you through creating mocks for the books resource, letting you choose which endpoints and fields to generate.


6. CRUD Operations with Data Persistence

Create complete CRUD endpoints with in-memory data persistence using the crud command:

mockadin crud [resource-name]

Options:

  • --fields <fields> - Comma-separated list of fields (e.g., "name,email,age")
  • --count <count> - Number of initial records to generate (default: 5)

Example:

# Create CRUD for products with specific fields
mockadin crud products --fields "name,price,category" --count 3

# Create CRUD for users (interactive)
mockadin crud users

This creates complete CRUD endpoints with data persistence:

  • GET /products - List all records
  • GET /products/:id - Get specific record
  • POST /products - Create new record
  • PUT /products/:id - Update record
  • DELETE /products/:id - Delete record

Features:

  • In-memory data persistence - Data persists during server session
  • Automatic ID generation - Unique IDs for each record
  • Timestamps - createdAt and updatedAt fields
  • Validation - Returns 404 for non-existent records
  • Hot-reload - Changes reflected automatically

Example API Usage:

# Create a product
curl -X POST http://localhost:4000/products \\
  -H "Content-Type: application/json" \\
  -d '{"name": "iPhone 15", "price": 999.99, "category": "Electronics"}'

# List all products
curl http://localhost:4000/products

# Get specific product
curl http://localhost:4000/products/1

# Update product
curl -X PUT http://localhost:4000/products/1 \\
  -H "Content-Type: application/json" \\
  -d '{"price": 899.99}'

# Delete product
curl -X DELETE http://localhost:4000/products/1

7. Usage Examples

a) Static JSON Mock

Create a file mocks/get/users.json:

[
  { "id": 1, "name": "Alice" },
  { "id": 2, "name": "Bob" }
]

Requesting GET /users will return this JSON.


b) Dynamic JS Handler

Create a file mocks/post/orders.js:

export default (req, res) => {
  const { product, quantity } = req.body;
  res.json({
    orderId: Math.floor(Math.random() * 10000),
    product,
    quantity,
    status: "created"
  });
};

Requesting POST /orders with a JSON body will return a dynamic response.


8. Route Mapping

Routes are mapped based on the folder structure:

  • mocks/get/users.jsonGET /users
  • mocks/post/orders.jsPOST /orders
  • mocks/get/products.jsonGET /products
  • mocks/put/users.jsPUT /users
  • mocks/delete/users.jsDELETE /users

Dynamic Routes (CRUD)

For CRUD operations, dynamic routes are automatically created:

  • mocks/get/products/[id].jsGET /products/:id
  • mocks/put/products/[id].jsPUT /products/:id
  • mocks/delete/products/[id].jsDELETE /products/:id

Nested Routes

You can nest folders for more complex routes:

  • mocks/get/admin/users.jsonGET /admin/users
  • mocks/post/orders/items.jsPOST /orders/items

Supported HTTP Methods

  • Place your mock files inside one of these folders:
    • get/GET
    • post/POST
    • put/PUT
    • delete/DELETE

The file name (without extension) and subfolders define the endpoint path.


9. Links


10. License

MIT © Lucas Marques