Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • NodeJS Tutorial
  • NodeJS Exercises
  • NodeJS Assert
  • NodeJS Buffer
  • NodeJS Console
  • NodeJS Crypto
  • NodeJS DNS
  • NodeJS File System
  • NodeJS Globals
  • NodeJS HTTP
  • NodeJS HTTP2
  • NodeJS OS
  • NodeJS Path
  • NodeJS Process
  • NodeJS Query String
  • NodeJS Stream
  • NodeJS String Decoder
  • NodeJS Timers
  • NodeJS URL
  • NodeJS Interview Questions
  • NodeJS Questions
  • Web Technology
Open In App
Next Article:
Generating Errors using HTTP-errors module in Node.js
Next article icon

How to Generate fake data using Faker module in Node.js ?

Last Updated : 16 Aug, 2021
Comments
Improve
Suggest changes
Like Article
Like
Report

Faker module is used to generate fake data, not only fake data, infect well organized fake data. Faker module is a widely used NPM module that can generate fake names, addresses, product names, prices with all these you can also generate fake IP addresses, images, and much more using this faker package.
Command to install faker module: 
 

npm install faker

There are some predefined context for which fake data are created for a particular context as mentioned below:

 

Context(object) Aspect(method)
name firstName, lastName, findName, suffix, jobTitle, jobDiscriptor
address latitude, longitude, country, state, city, zipCode, streetName
commerce product, productName, price, productMaterial
finance account, accountName, amount, currencyName, currencyCode, transactionType
image people, nature, sports, animals, fashion, food, nightLife
internet email, url, ip, mac, password, domainName

Syntax to get fake data 
 

faker.context.aspect()

Example 1: 
 

javascript




// Program to generate some fake
// names with their job titles
  
// Requiring faker module
const faker = require('faker')
  
for(let i=0; i<8; i++){
 
// Fake first name
  const firstName = faker.name.firstName()
 
// Fake last name
  const lastName = faker.name.lastName()
 
// Fake suffix
  const suffix = faker.name.suffix()
 
// Fake job Title
  const jobTitle = faker.name.jobTitle()
  
  console.log(`${suffix} ${firstName}
    ${lastName} works as '${jobTitle}'`)
}
 
 

Output: 
 

Example 2: 
 

javascript




// Program to generate some fake
// products with their details
 
// Requiring faker module
const faker = require('faker')
 
for (let i = 0; i < 8; i++) {
 
    // Fake product name
    const product = faker.commerce.product()
    // fake price of that product
    const price = faker.commerce.price()
 
    // Fake details
    const productMaterial =
        faker.commerce.productMaterial()
    console.log(`${product} made with
        ${productMaterial}, price ${price}$`)
}
 
 

Output: 
 

Example 3: 
 

javascript




// Program to generate some fake
// bank transaction details
 
// Requiring faker module
const faker = require('faker')
 
for (let i = 0; i < 8; i++) {
 
    // Fake account type
    const ac = faker.finance.account()
 
    // Fake account name
    const acName = faker.finance.accountName()
 
    // Fake transaction type
    const tT = faker.finance.transactionType()
 
    // Fake amount transaction
    const amt = faker.finance.amount()
 
    console.log(`${acName}, Account No-${ac},
    transaction Type-${tT}, Amount-${amt}`)
}
 
 

Output: 
 

Example 4: 
 

javascript




// Program to generate some fake
// domain name and ip addresses
 
// Requiring faker module
const faker = require('faker')
 
for (let i = 0; i < 8; i++) {
 
    // Fake ip address
    const ip = faker.internet.ip()
 
    // Fake domain name
    const domainName =
        faker.internet.domainName()
 
    console.log(`Domain name ->
        ${domainName}, ip-address-> ${ip}`)
}
 
 

Output: 
 

Reference: NPM faker package
 



Next Article
Generating Errors using HTTP-errors module in Node.js
author
hunter__js
Improve
Article Tags :
  • Node.js
  • Web Technologies
  • Node.js-Misc

Similar Reads

  • Generating Errors using HTTP-errors module in Node.js
    HTTP-errors module is used for generating errors for Node.js applications. It is very easy to use. We can use it with the express, Koa, etc. applications. We will implement this module in an express application. Installation and Setup: First, initialize the application with the package.json file wit
    2 min read
  • How to Add Data in JSON File using Node.js ?
    JSON stands for Javascript Object Notation. It is one of the easiest ways to exchange information between applications and is generally used by websites/APIs to communicate. For getting started with Node.js, refer this article. Prerequisites:NPM NodeApproachTo add data in JSON file using the node js
    4 min read
  • How to Validate Data using joi Module in Node.js ?
    Joi module is a popular module for data validation. This module validates the data based on schemas. There are various functions like optional(), required(), min(), max(), etc which make it easy to use and a user-friendly module for validating the data. Introduction to joi It's easy to get started a
    3 min read
  • How to Validate Data using express-validator Module in Node.js ?
    Validation in node.js can be easily done by using the express-validator module. This module is popular for data validation. There are other modules available in market like hapi/joi, etc but express-validator is widely used and popular among them.Steps to install express-validator module:   You can
    3 min read
  • How to add new functionalities to a module in Node.js ?
    Node.js is an open-source and cross-platform runtime environment built on Chrome’s V8 JavaScript engine for executing JavaScript code outside of a browser. You need to recollect that NodeJS isn’t a framework, and it’s not a programming language. In this article, we will discuss how to add new functi
    3 min read
  • How to Generate or Send JSON Data at the Server Side using Node.js ?
    In modern web development, JSON (JavaScript Object Notation) is the most commonly used format for data exchange between a server and a client. Node.js, with its powerful runtime and extensive ecosystem, provides robust tools for generating and sending JSON data on the server side. This guide will wa
    3 min read
  • How to Build Password Generator using Node.js?
    Creating a password generator is a common and practical programming task that helps enhance security by generating random passwords. Using Node.js, you can build a simple and effective password generator with various features, such as customizable length, inclusion of special characters, and more. T
    3 min read
  • How to Validate Data using validator Module in Node.js ?
    The Validator module is popular for validation. Validation is necessary to check whether the data is correct or not, so this module is easy to use and validates data quickly and easily.  Feature of validator module: It is easy to get started and easy to use.It is a widely used and popular module for
    2 min read
  • How to Generate Random and Unique Password in Node.js using 'generate-password' NPM Module?
    The generate-password module provides a simple and flexible way to generate random passwords. It offers various options to customize the length, complexity, and character set of the generated passwords. This makes it a great tool for developers who need to implement password generation in their appl
    2 min read
  • How To Create Modules in NodeJS?
    Modules are the building blocks of NodeJS code. They help you break down your project into smaller, manageable pieces, each with its own job. To create a module, just make a JavaScript file and export what you want to share. Other files can then import and use those exports, adding that functionalit
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences