Skip to content
On this page


This is Faker's main class containing all modules that can be used to generate data.

Please have a look at the individual modules and methods for more information and examples.


Creates a new instance of Faker.

In most cases you should use one of the prebuilt Faker instances instead of the constructor, for example fakerDE, fakerFR, ...

You only need to use the constructor if you need custom fallback logic or a custom locale.

For more information see our Localization Guide.


options{ ... } | { ... }

The options to use.

options.localeLocaleDefinition | LocaleDefinition[]

The locale data to use for this instance. If an array is provided, the first locale that has a definition for a given property will be used.


The name of the main locale to use.

DEPRECATED: Use new Faker({ locale: [locale, localeFallback] }) instead.


The name of the fallback locale to use.

DEPRECATED: Use new Faker({ locale: [locale, localeFallback] }) instead.

options.localesRecord<string, LocaleDefinition>

The locale data to use for this instance.

DEPRECATED: Use new Faker({ locale: [locale, localeFallback] }) instead.

Returns: Faker

new Faker(options: {
  locale: LocaleDefinition | LocaleDefinition[]
} | {
  locale: string,
  localeFallback: string,
  locales: Record<string, LocaleDefinition>
}): Faker
import { Faker, es } from '@faker-js/faker';
// const { Faker, es } = require('@faker-js/faker');

// create a Faker instance with only es data and no en fallback (=> smaller bundle size)
const customFaker = new Faker({ locale: [es] });

customFaker.person.firstName(); // 'Javier'
customFaker.person.lastName(); // 'Ocampo Corrales'; // throws Error as this data is not available in `es`


Sets the seed or generates a new one.

Please note that generated values are dependent on both the seed and the number of calls that have been made since it was set.

This method is intended to allow for consistent values in a tests, so you might want to use hardcoded values as the seed.

In addition to that it can be used for creating truly random tests (by passing no arguments), that still can be reproduced if needed, by logging the result and explicitly setting it if needed.


seed?number | number[]Math.ceil(Math.random() * Number.MAX_SAFE_INTEGER)

The seed or seed array to use.

Returns: number | number[]

faker.seed(seed?: number | number[] = Math.ceil(Math.random() * Number.MAX_SAFE_INTEGER)): number | number[]
// Consistent values for tests (using a number):
faker.seed(42); // 4; // 8

faker.seed(42); // 4; // 8

// Consistent values for tests (using an array):
faker.seed([42, 13, 17]); // 4; // 8

faker.seed([42, 13, 17]); // 4; // 8

// Random but reproducible tests:
// Simply log the seed, and if you need to reproduce it, insert the seed here
console.log('Running test with seed:', faker.seed());


Sets the refDate source to use if no refDate date is passed to the date methods.


dateOrSource(() => Date) | Date | number | string() => new Date()

The function or the static value used to generate the refDate date instance. The function must return a new valid Date instance for every call.

Returns: void

faker.setDefaultRefDate(dateOrSource: (() => Date) | Date | number | string = () => new Date()): void

// Default behavior
// faker.setDefaultRefDate();; // Changes based on the current date/time

// Use a static ref date
faker.setDefaultRefDate(new Date('2020-01-01'));; // Reproducible '2019-07-03T08:27:58.118Z'

// Use a ref date that changes every time it is used
let clock = new Date("2020-01-01").getTime();
faker.setDefaultRefDate(() => {
  clock += 1000; // +1s
  return new Date(clock);

faker.defaultRefDate() // 2020-01-01T00:00:01Z
faker.defaultRefDate() // 2020-01-01T00:00:02Z

Released under the MIT License.