Skip to content
On this page

Internet

Module to generate internet related entries.

avatar

Returns a random avatar url.

Available since v2.0.1

Returns: string

ts
faker.internet.avatar(): string
faker.internet.avatar() // => "https://cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHir...
faker.internet.avatar()
// 'https://cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye/avatar/315.jpg'

color

Generates a random css hex color code in aesthetically pleasing color palette.

Based on http://stackoverflow.com/questions/43044/algorithm-to-randomly-generate-an-aesthetically-pleasing-color-palette

Available since v2.0.1

Parameters

NameTypeDefaultDescription
redBasenumber0

The optional base red in range between 0 and 255.

greenBasenumber0

The optional base green in range between 0 and 255.

blueBasenumber0

The optional base blue in range between 0 and 255.

Returns: string

ts
faker.internet.color(redBase: number = 0, greenBase: number = 0, blueBase: number = 0): string
faker.internet.color() // => "#464c5b"
faker.internet.color() // '#30686e'
faker.internet.color(100, 100, 100) // '#4e5f8b'

domainName

Generates a random domain name.

Available since v2.0.1

Returns: string

ts
faker.internet.domainName(): string
faker.internet.domainName() // => "muddy-news.net"
faker.internet.domainName() // 'slow-timer.info'

domainSuffix

Returns a random domain suffix.

Available since v2.0.1

Returns: string

ts
faker.internet.domainSuffix(): string
faker.internet.domainSuffix() // => "name"
faker.internet.domainSuffix() // 'com'
faker.internet.domainSuffix() // 'name'

domainWord

Generates a random domain word.

Available since v2.0.1

Returns: string

ts
faker.internet.domainWord(): string
faker.internet.domainWord() // => "muddy-news"
faker.internet.domainWord() // 'close-reality'
faker.internet.domainWord() // 'weird-cytoplasm'

email

Generates an email address using the given person's name as base.

Available since v2.0.1

Parameters

NameTypeDefaultDescription
firstName?string

The optional first name to use. If not specified, a random one will be chosen.

lastName?string

The optional last name to use. If not specified, a random one will be chosen.

provider?string

The mail provider domain to use. If not specified, a random free mail provider will be chosen.

options?{ ... }{ allowSpecialCharacters: false }

The options to use.

options.allowSpecialCharacters?booleanfalse

Whether special characters such as .!#$%&'*+-/=?^_`{|}~ should be included in the email address.

Returns: string

ts
faker.internet.email(firstName?: string, lastName?: string, provider?: string, options?: {
  allowSpecialCharacters: boolean
} = { allowSpecialCharacters: false }): string
faker.internet.email() // => "Larue_Rau85@yahoo.com"
faker.internet.email() // 'Kassandra4@hotmail.com'
faker.internet.email('Jeanne', 'Doe') // 'Jeanne63@yahoo.com'
faker.internet.email('Jeanne', 'Doe', 'example.fakerjs.dev') // 'Jeanne_Doe88@example.fakerjs.dev'
faker.internet.email('Jeanne', 'Doe', 'example.fakerjs.dev', { allowSpecialCharacters: true }) // 'Jeanne%Doe88@example.fakerjs.dev'

emoji

Generates a random emoji.

Available since v6.2.0

Parameters

NameTypeDefaultDescription
options{ ... }{}

Options object.

options.types?readonly EmojiType[]

A list of the emoji types that should be used.

Returns: string

ts
faker.internet.emoji(options: {
  types: readonly EmojiType[]
} = {}): string
faker.internet.emoji() // => "💺"
faker.internet.emoji() // '🥰'
faker.internet.emoji({ types: ['food', 'nature'] }) // '🥐'

exampleEmail

Generates an email address using an example mail provider using the given person's name as base.

Available since v3.1.0

Parameters

NameTypeDefaultDescription
firstName?string

The optional first name to use. If not specified, a random one will be chosen.

lastName?string

The optional last name to use. If not specified, a random one will be chosen.

options?{ ... }{ allowSpecialCharacters: false }

The options to use.

options.allowSpecialCharacters?booleanfalse

Whether special characters such as .!#$%&'*+-/=?^_`{|}~ should be included in the email address.

Returns: string

ts
faker.internet.exampleEmail(firstName?: string, lastName?: string, options?: {
  allowSpecialCharacters: boolean
} = { allowSpecialCharacters: false }): string
faker.internet.exampleEmail() // => "Larue_Rau85@example.com"
faker.internet.exampleEmail() // 'Helmer.Graham23@example.com'
faker.internet.exampleEmail('Jeanne', 'Doe') // 'Jeanne96@example.net'
faker.internet.exampleEmail('Jeanne', 'Doe', { allowSpecialCharacters: true }) // 'Jeanne%Doe88@example.com'

httpMethod

Returns a random http method.

Can be either of the following:

  • GET
  • POST
  • PUT
  • DELETE
  • PATCH

Available since v5.4.0

Returns: 'DELETE' | 'GET' | 'PATCH' | 'POST' | 'PUT'

ts
faker.internet.httpMethod(): "GET" | "POST" | "PUT" | "DELETE" | "PATCH"
faker.internet.httpMethod() // => "PUT"
faker.internet.httpMethod() // 'PATCH'

httpStatusCode

Generates a random HTTP status code.

Available since v7.0.0

Parameters

NameTypeDefaultDescription
options{ ... }{}

Options object.

options.types?readonly HTTPStatusCodeType[]

A list of the HTTP status code types that should be used.

Returns: number

ts
faker.internet.httpStatusCode(options: {
  types: readonly HTTPStatusCodeType[]
} = {}): number
faker.internet.httpStatusCode() // => 305
faker.internet.httpStatusCode() // 200
faker.internet.httpStatusCode({ types: ['success', 'serverError'] }) // 500

ip

Generates a random IPv4 address.

Available since v2.0.1

Returns: string

ts
faker.internet.ip(): string
faker.internet.ip() // => "140.151.183.216"
faker.internet.ip() // '245.108.222.0'

ipv4

Generates a random IPv4 address.

Available since v6.1.1

Returns: string

ts
faker.internet.ipv4(): string
faker.internet.ipv4() // => "140.151.183.216"
faker.internet.ipv4() // '245.108.222.0'

ipv6

Generates a random IPv6 address.

Available since v4.0.0

Returns: string

ts
faker.internet.ipv6(): string
faker.internet.ipv6() // => "89bd:9d8d:69a6:74e0:f467:cc87:96ed:151a"
faker.internet.ipv6() // '269f:1230:73e3:318d:842b:daab:326d:897b'

mac

Generates a random mac address.

Available since v3.0.0

Parameters

NameTypeDefaultDescription
sep?string':'

The optional separator to use. Can be either ':', '-' or ''.

Returns: string

ts
faker.internet.mac(sep?: string = ':'): string
faker.internet.mac() // => "89:bd:9d:8d:69:a6"
faker.internet.mac() // '32:8e:2e:09:c6:05'

password

Generates a random password.

Available since v2.0.1

Parameters

NameTypeDefaultDescription
lennumber15

The length of the password to generate.

memorablebooleanfalse

Whether the generated password should be memorable.

patternRegExp/\w/

The pattern that all chars should match should match. This option will be ignored, if memorable is true.

prefixstring''

The prefix to use.

Returns: string

ts
faker.internet.password(len: number = 15, memorable: boolean = false, pattern: RegExp = /\w/, prefix: string = ''): string
faker.internet.password() // => "UYdqZrTqIEJuENl"
faker.internet.password() // '89G1wJuBLbGziIs'
faker.internet.password(20) // 'aF55c_8O9kZaPOrysFB_'
faker.internet.password(20, true) // 'lawetimufozujosodedi'
faker.internet.password(20, true, /[A-Z]/) // 'HMAQDFFYLDDUTBKVNFVS'
faker.internet.password(20, true, /[A-Z]/, 'Hello ') // 'Hello IREOXTDWPERQSB'

port

Generates a random port number.

Available since v5.4.0

Returns: number

ts
faker.internet.port(): number
faker.internet.port() // => 35967
faker.internet.port() // '9414'

protocol

Returns a random web protocol. Either http or https.

Available since v2.1.5

Returns: 'http' | 'https'

ts
faker.internet.protocol(): "http" | "https"
faker.internet.protocol() // => "https"
faker.internet.protocol() // 'http'
faker.internet.protocol() // 'https'

url

Generates a random url.

Available since v2.1.5

Returns: string

ts
faker.internet.url(): string
faker.internet.url() // => "https://opulent-rabbit.org"
faker.internet.url() // 'https://remarkable-hackwork.info'

userAgent

Generates a random user agent string.

Available since v2.0.1

Returns: string

ts
faker.internet.userAgent(): string
faker.internet.userAgent() // => "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT...
faker.internet.userAgent()
// 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_8_8)  AppleWebKit/536.0.2 (KHTML, like Gecko) Chrome/27.0.849.0 Safari/536.0.2'

userName

Generates a username using the given person's name as base.

Available since v2.0.1

Parameters

NameTypeDefaultDescription
firstName?string

The optional first name to use. If not specified, a random one will be chosen.

lastName?string

The optional last name to use. If not specified, a random one will be chosen.

Returns: string

ts
faker.internet.userName(firstName?: string, lastName?: string): string
faker.internet.userName() // => "Katharina_Medhurst60"
faker.internet.userName() // 'Nettie_Zboncak40'
faker.internet.userName('Jeanne', 'Doe') // 'Jeanne98'

Released under the MIT License.