@sharoussh/mock-api-server
v1.0.0
Published
Zero-dependency CLI to spin up a mock REST API server from a JSON file
Maintainers
Readme
mock-api-server
Zero-dependency CLI to spin up a mock REST API server instantly from a JSON config file. Perfect for frontend development and testing.
Install
npm install -g mock-api-serverOr run without installing:
npx mock-api-server --init
npx mock-api-server mock-api.jsonQuick start
# 1. Create a sample config
mock-api --init
# 2. Start the server
mock-api mock-api.json
# Output:
# mock-api running on http://localhost:3000
# GET /users → 200
# POST /users → 201
# GET /users/:id → 200
# ...Config format
Create a mock-api.json file:
{
"GET /users": {
"status": 200,
"body": [
{ "id": 1, "name": "Alice" },
{ "id": 2, "name": "Bob" }
]
},
"GET /users/:id": {
"status": 200,
"body": { "id": "{id}", "name": "Alice" }
},
"POST /users": {
"status": 201,
"body": { "message": "User created", "id": 3 }
},
"DELETE /users/:id": {
"status": 204,
"body": {}
}
}URL parameters
Use {param} in response body to echo back URL params:
"GET /users/:id": {
"status": 200,
"body": { "id": "{id}", "name": "Alice" }
}GET /users/42 → { "id": "42", "name": "Alice" }
Options
| Flag | Description | Default |
|------|-------------|---------|
| --port=N | Port to listen on | 3000 |
| --delay=N | Add N ms delay to responses | 0 |
| --quiet | Suppress request logs | off |
| --init | Create a sample mock-api.json | — |
| --help | Show help | — |
Features
- ✅ URL params (
:id,:slug, etc.) - ✅ All HTTP methods (GET, POST, PUT, PATCH, DELETE)
- ✅ CORS headers — works with any frontend out of the box
- ✅ Simulated delay with
--delay - ✅ Custom status codes per route
- ✅ Zero dependencies — pure Node.js
Running tests
npm testLicense
MIT
