Generate realistic mock data (Faker.js)
✓Works with OpenClaudeYou are a JavaScript mock data generation specialist. The user wants to generate realistic mock data using Faker.js for testing and development purposes.
What to check first
- Run
npm list fakerto verify Faker.js is installed (v8.0.0+ recommended) - Check your Node.js version with
node --version(v14+ required for ESM support)
Steps
- Install Faker.js with
npm install @faker-js/faker(oryarn add @faker-js/faker) - Import the Faker library at the top of your file:
import { faker } from '@faker-js/faker' - Choose your locale with
faker.setLocale('en_US')or other supported locales before generating data - Create a function that returns an object with faker methods for the data structure you need
- Call faker methods like
faker.person.firstName(),faker.internet.email(),faker.location.city()for specific data types - For arrays of mock data, wrap your object generator in a loop or
.Array.from()with a count - Export the function or data array for use in your test files or seed scripts
- Test by logging output or writing to a JSON file to verify realistic data generation
Code
import { faker } from '@faker-js/faker';
// Set locale (optional, defaults to en_US)
faker.setLocale('en_US');
// Single user mock data generator
function generateMockUser() {
return {
id: faker.string.uuid(),
firstName: faker.person.firstName(),
lastName: faker.person.lastName(),
email: faker.internet.email(),
password: faker.internet.password({ length: 12, memorable: false }),
phone: faker.phone.number(),
avatar: faker.image.avatar(),
birthDate: faker.date.birthdate({ min: 18, max: 80, mode: 'age' }),
address: {
street: faker.location.streetAddress(),
city: faker.location.city(),
state: faker.location.state(),
zipCode: faker.location.zipCode(),
country: faker.location.country()
},
company: faker.company.name(),
jobTitle: faker.person.jobTitle(),
createdAt: faker.date.past(),
updatedAt: faker.date.recent()
};
}
// Generate array of mock users
function generateMockUsers(count = 10) {
return Array.from({ length: count }, () => generateMockUser());
}
// Mock product generator
function generateMockProduct() {
return {
id: faker.string.uuid(),
name: faker.commerce.productName(),
description: faker.commerce.productDescription(),
price: parseFloat(faker.commerce.price({ min: 10, max: 500 })),
category: faker.commerce.department(),
stock:
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Code Generation Skills
Other Claude Code skills in the same category — free to download.
Type Generator
Generate TypeScript types from JSON/API responses
Interface from JSON
Generate interfaces from JSON samples
Enum Generator
Generate enums from constant values
Boilerplate Reducer
Generate boilerplate code patterns
Regex Builder
Build and test regular expressions
SQL Generator
Generate SQL queries from natural language
Type Guard Generator
Generate TypeScript type guards
Regex Lookahead
Write regex with lookaheads, lookbehinds, and named groups
Want a Code Generation skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.