Free 40-page Claude guide — setup, 120 prompt codes, MCP servers, AI agents. Download free →
CLSkills
Code GenerationbeginnerNew

Mock Data Generator

Share

Generate realistic mock data (Faker.js)

Works with OpenClaude

You 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 faker to verify Faker.js is installed (v8.0.0+ recommended)
  • Check your Node.js version with node --version (v14+ required for ESM support)

Steps

  1. Install Faker.js with npm install @faker-js/faker (or yarn add @faker-js/faker)
  2. Import the Faker library at the top of your file: import { faker } from '@faker-js/faker'
  3. Choose your locale with faker.setLocale('en_US') or other supported locales before generating data
  4. Create a function that returns an object with faker methods for the data structure you need
  5. Call faker methods like faker.person.firstName(), faker.internet.email(), faker.location.city() for specific data types
  6. For arrays of mock data, wrap your object generator in a loop or .Array.from() with a count
  7. Export the function or data array for use in your test files or seed scripts
  8. 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

Quick Info

Difficultybeginner
Version1.0.0
AuthorClaude Skills Hub
codegenmock-datafaker

Install command:

curl -o ~/.claude/skills/mock-data-generator.md https://claude-skills-hub.vercel.app/skills/code-generation/mock-data-generator.md

Related Code Generation Skills

Other Claude Code skills in the same category — free to download.

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.