Generate Test Data for Express.js APIs
The Problem
Express APIs need test data for development, demos, and testing. Without a seeded database, your GET endpoints return empty arrays and your frontend developers are blocked. Building a seed script means picking a Faker library, wiring up database connections, handling foreign keys manually, and hoping the data looks realistic enough.
For API-first teams, the problem compounds. You need consistent data across services, and each service has its own seed script with its own bugs.
The Solution: MockHero API
MockHero is itself an API, so it fits naturally into Express workflows. One HTTP call returns JSON you can write to any database or return directly as a mock endpoint during development.
Quick Setup
curl -X POST https://api.mockhero.dev/api/v1/generate \
-H "x-api-key: mh_your_api_key" \
-H "Content-Type: application/json" \
-d '{
"tables": [
{
"name": "customers",
"count": 10,
"fields": [
{ "name": "id", "type": "uuid" },
{ "name": "name", "type": "full_name" },
{ "name": "email", "type": "email" },
{ "name": "plan", "type": "enum", "params": { "values": ["starter","growth","enterprise"] } }
]
},
{
"name": "orders",
"count": 30,
"fields": [
{ "name": "id", "type": "uuid" },
{ "name": "customer_id", "type": "ref", "params": { "ref": "customers.id" } },
{ "name": "total", "type": "decimal", "params": { "min": 10, "max": 500 } },
{ "name": "status", "type": "enum", "params": { "values": ["pending","shipped","delivered"] } }
]
}
],
"format": "json"
}'
Step-by-Step Guide
1. Install dependencies
npm install express better-sqlite3
2. Get your MockHero API key
Sign up at mockhero.dev/sign-up.
3. Write the seed script
Create seed.mjs that creates SQLite tables, fetches data from MockHero, and inserts the records.
4. Run it
node seed.mjs
5. Query from Express
Your Express routes now read from a pre-populated database with realistic data.
Complete Example
The seed script creates tables, fetches data from MockHero, and inserts it into SQLite. Your Express routes then serve realistic data from the database.
Why MockHero vs Faker / Manual Seeds
- API-native — MockHero is an API seeding an API. No library installation needed.
- Database agnostic — works with SQLite, Postgres, MongoDB, or any database you use with Express.
- Team consistency — everyone seeds from the same schema, same deterministic seed.
Get Started
Free tier, no credit card. Sign up at mockhero.dev and seed your Express API in minutes.
MockHero Team
Guides and tutorials for generating realistic test data with the MockHero API.
Start generating test data for free
1,000 rows/month on the free tier. No credit card required.
Get Your API Key