Generate massive amounts of fake contextual data for testing and development purposes
npx @tessl/cli install tessl/npm-faker-js--faker@10.0.0Faker.js is a comprehensive fake data generation library that enables developers to create realistic test data for applications and development environments. It provides extensive modules for generating person data, location data, financial information, internet-related data, and various other data types with support for over 70 locales.
npm install @faker-js/fakerimport { faker } from "@faker-js/faker";For locale-specific instances:
import { fakerDE, fakerFR, fakerJA } from "@faker-js/faker";For simple faker without locale data:
import { simpleFaker } from "@faker-js/faker";For CommonJS:
const { faker } = require("@faker-js/faker");import { faker } from "@faker-js/faker";
// Set seed for reproducible results
faker.seed(123);
// Generate person data
const firstName = faker.person.firstName();
const lastName = faker.person.lastName();
const email = faker.internet.email({ firstName, lastName });
// Generate location data
const address = faker.location.streetAddress();
const city = faker.location.city();
const zipCode = faker.location.zipCode();
// Generate financial data
const amount = faker.finance.amount({ min: 100, max: 1000, dec: 2 });
const creditCard = faker.finance.creditCardNumber();
// Generate dates
const birthDate = faker.date.birthdate({ min: 18, max: 65, mode: 'age' });
const futureDate = faker.date.future();
console.log({
name: `${firstName} ${lastName}`,
email,
address: `${address}, ${city} ${zipCode}`,
amount,
creditCard,
birthDate,
futureDate
});Faker.js is built around several key components:
Generate realistic person information including names, demographics, and professional details with full locale support.
interface PersonModule {
firstName(sex?: SexType): string;
lastName(sex?: SexType): string;
fullName(options?: { firstName?: string; lastName?: string; sex?: SexType }): string;
prefix(sex?: SexType): string;
suffix(): string;
jobTitle(): string;
bio(): string;
}Generate internet-related data including emails, URLs, IP addresses, and tech-related information.
interface InternetModule {
email(options?: { firstName?: string; lastName?: string; provider?: string }): string;
username(options?: { firstName?: string; lastName?: string }): string;
url(options?: { appendSlash?: boolean; protocol?: string }): string;
ip(): string;
ipv4(options?: { network?: IPv4NetworkType; cidrBlock?: string }): string;
mac(options?: { separator?: string }): string;
password(options?: { length?: number; memorable?: boolean; pattern?: RegExp }): string;
}Generate location data including addresses, coordinates, and geographic information with locale-specific formatting.
interface LocationModule {
city(): string;
country(options?: { variant?: 'common' | 'official' }): string;
streetAddress(options?: { useFullAddress?: boolean }): string;
zipCode(options?: { state?: string; format?: string }): string;
latitude(options?: { max?: number; min?: number; precision?: number }): number;
longitude(options?: { max?: number; min?: number; precision?: number }): number;
}Generate financial information including bank accounts, currencies, cryptocurrency addresses, and transaction data.
interface FinanceModule {
amount(options?: { min?: number; max?: number; dec?: number; symbol?: string }): string;
accountNumber(options?: { length?: number }): string;
creditCardNumber(options?: { issuer?: string }): string;
currency(): Currency;
bitcoinAddress(options?: { type?: BitcoinAddressFamilyType; network?: BitcoinNetworkType }): string;
ethereumAddress(): string;
}Generate date and time data with locale-aware formatting and flexible range options.
interface DateModule {
anytime(options?: { refDate?: Date }): Date;
past(options?: { years?: number; refDate?: Date }): Date;
future(options?: { years?: number; refDate?: Date }): Date;
birthdate(options?: { min?: number; max?: number; mode?: 'age' | 'year' }): Date;
between(options: { from: Date; to: Date }): Date;
}Core data generation utilities including numbers, strings, booleans, and helper functions for arrays and objects.
interface NumberModule {
int(options?: { min?: number; max?: number; multipleOf?: number }): number;
float(options?: { min?: number; max?: number; multipleOf?: number; precision?: number }): number;
bigInt(options?: { min?: bigint; max?: bigint }): bigint;
}
interface StringModule {
alpha(options?: { length?: number; casing?: Casing; exclude?: string[] }): string;
alphanumeric(options?: { length?: number; casing?: Casing }): string;
uuid(): string;
nanoid(options?: { min?: number; max?: number }): string;
}Generate business and e-commerce related data including products, prices, and company information.
interface CommerceModule {
productName(): string;
price(options?: { min?: number; max?: number; dec?: number; symbol?: string }): string;
department(): string;
productDescription(): string;
}
interface CompanyModule {
name(): string;
catchPhrase(): string;
buzzPhrase(): string;
companySuffix(): string;
}Generate various types of text content including Lorem ipsum, individual words, and hacker terminology.
interface LoremModule {
word(options?: { length?: number; strategy?: string }): string;
words(count?: number): string;
sentence(wordCount?: number): string;
paragraph(sentenceCount?: number): string;
text(): string;
slug(wordCount?: number): string;
}
interface WordModule {
adjective(options?: { length?: number; strategy?: string }): string;
adverb(options?: { length?: number; strategy?: string }): string;
conjunction(options?: { length?: number; strategy?: string }): string;
interjection(options?: { length?: number; strategy?: string }): string;
noun(options?: { length?: number; strategy?: string }): string;
preposition(options?: { length?: number; strategy?: string }): string;
verb(options?: { length?: number; strategy?: string }): string;
}
interface HackerModule {
abbreviation(): string;
adjective(): string;
noun(): string;
verb(): string;
ingverb(): string;
phrase(): string;
}Generate visual and media-related data including colors and image URLs.
interface ColorModule {
rgb(options?: { format?: 'css' | 'binary' | 'decimal'; casing?: 'lower' | 'upper' | 'mixed' }): string;
cmyk(options?: { format?: 'css' | 'binary' }): string;
hsl(options?: { format?: 'css' | 'binary' }): string;
hwb(options?: { format?: 'css' | 'binary' }): string;
lab(options?: { format?: 'css' | 'binary' }): string;
lch(options?: { format?: 'css' | 'binary' }): string;
colorByCSSColorSpace(space?: string, format?: string): string;
cssSupportedFunction(): string;
cssSupportedSpace(): string;
human(): string;
}
interface ImageModule {
avatar(): string;
avatarGitHub(): string;
avatarLegacy(): string;
dataUri(options?: { width?: number; height?: number; color?: string }): string;
url(options?: { width?: number; height?: number }): string;
urlLoremFlickr(options?: { width?: number; height?: number; category?: string }): string;
urlPicsumPhotos(options?: { width?: number; height?: number; grayscale?: boolean; blur?: number }): string;
urlPlaceholder(options?: { width?: number; height?: number; backgroundColor?: string; textColor?: string; format?: string; text?: string }): string;
}Generate system, database, and technical data for development and testing scenarios.
interface DatabaseModule {
column(): string;
type(): string;
collation(): string;
engine(): string;
mongodbObjectId(): string;
}
interface PhoneModule {
number(options?: { style?: 'human' | 'national' | 'international' }): string;
}Specialized modules for various domains including vehicles, animals, books, food, music, and scientific data.
interface VehicleModule {
manufacturer(): string;
model(): string;
type(): string;
vin(): string;
vrm(): string;
}
interface ScienceModule {
chemicalElement(): ChemicalElement;
unit(): Unit;
chemicalFormula(): string;
}type SexType = 'female' | 'male';
type Casing = 'upper' | 'lower' | 'mixed';
enum IPv4Network {
Any = 'any',
Loopback = 'loopback',
PrivateA = 'private-a',
PrivateB = 'private-b',
PrivateC = 'private-c',
TestNet1 = 'test-net-1',
TestNet2 = 'test-net-2',
TestNet3 = 'test-net-3',
LinkLocal = 'link-local',
Multicast = 'multicast'
}
type IPv4NetworkType = keyof typeof IPv4Network;
enum BitcoinAddressFamily {
Legacy = 'legacy',
Segwit = 'segwit',
Bech32 = 'bech32',
Taproot = 'taproot'
}
type BitcoinAddressFamilyType = keyof typeof BitcoinAddressFamily;
enum BitcoinNetwork {
Mainnet = 'mainnet',
Testnet = 'testnet'
}
type BitcoinNetworkType = keyof typeof BitcoinNetwork;
interface Currency {
code: string;
name: string;
symbol: string;
numericCode: string;
}
interface FakerOptions {
locale?: LocaleDefinition;
randomizer?: Randomizer;
seed?: number | number[];
}
interface Randomizer {
next(): number;
seed(seed?: number | number[]): void;
}Faker.js includes comprehensive locale support with 74+ locales. Each locale provides culturally appropriate data for names, addresses, phone numbers, and other region-specific information.
const faker: Faker; // Default English locale instance// Major locales
const fakerEN: Faker; // English (US)
const fakerDE: Faker; // German
const fakerFR: Faker; // French
const fakerES: Faker; // Spanish
const fakerJA: Faker; // Japanese
const fakerZH_CN: Faker; // Chinese (Simplified)
const fakerPT_BR: Faker; // Portuguese (Brazil)
// All available locales
const allFakers: Record<string, Faker>;/**
* Merge multiple locale definitions into a single locale
* @param locales - Array of locale definitions to merge
* @returns Merged locale definition
*/
function mergeLocales(locales: LocaleDefinition[]): LocaleDefinition;/**
* Generate a 32-bit Mersenne Twister randomizer
* @param seed - Optional seed value
* @returns Randomizer instance
*/
function generateMersenne32Randomizer(seed?: number): Randomizer;
/**
* Generate a 53-bit Mersenne Twister randomizer (default)
* @param seed - Optional seed value
* @returns Randomizer instance
*/
function generateMersenne53Randomizer(seed?: number): Randomizer;/**
* Custom error class for faker-specific errors
*/
class FakerError extends Error {
constructor(message: string, cause?: unknown);
}For applications that don't need locale support, SimpleFaker provides core functionality:
interface SimpleFaker {
datatype: DatatypeModule;
date: SimpleDateModule;
helpers: SimpleHelpersModule;
location: SimpleLocationModule;
number: NumberModule;
string: StringModule;
seed(seed?: number | number[]): void;
setDefaultRefDate(dateOrSource?: string | Date | number): void;
}
const simpleFaker: SimpleFaker;