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.
- π― 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
npm install -g cli-mockserverOr use locally in your project:
npm install --save-dev cli-mockservermockserver initChoose from templates:
- π± Social Media (posts, comments, users, likes, etc.)
- π E-commerce (products, orders, cart)
- π Basic (simple REST endpoints)
mockserver startYour mock API is now running at http://localhost:9500!
curl http://localhost:9500/api/users
curl http://localhost:9500/api/posts
curl http://localhost:9500/api/posts/123/commentsmockserver 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 changesmockserver init [options]
Options:
-t, --template <name> Use template (social, ecommerce, basic)
-f, --force Overwrite existing schemamockserver validate [options]
Options:
-s, --schema <path> Path to schema filemockserver infomockserver generate [options]
Options:
-o, --output <dir> Output directory (default: ./mock-data)MockChaos supports 20+ field types:
uuid- Unique identifieremail- Email addressusername- UsernamefirstName- First namelastName- Last namesentence- Random sentenceparagraph- Random paragraphword- Random wordavatar- Avatar image URLimage- Random image URLurl- Random URLcity- City nametimezone- Timezone stringboolean- true/false
date:past- Past datedate:recent- Recent date (last few days)date:future- Future datedate:recent:nullable- Recent date or null
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)
{
"fields": {
"user": {
"id": "uuid",
"name": "firstName",
"email": "email"
}
}
}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"
}
}
]
}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=10Response includes pagination metadata:
{
"data": [...],
"pagination": {
"page": 2,
"limit": 10,
"total": 100,
"totalPages": 10,
"hasNext": true,
"hasPrev": true
}
}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"
}
}
]
}# 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 startContributions are welcome! Please feel free to submit a Pull Request.
BSD-3-Clause License - feel free to use this in your projects!
- Powered by Faker.js for realistic data generation
- Built with Express and Commander
- Beautiful CLI with Chalk and Ora
Made with β€οΈ for frontend developers who are tired of waiting for backend APIs