Node.js Express Fake Data Generator in CSV File App Using Faker.js and objects-to-csv Library Full Tutorial

Node.js Express Fake Data Generator in CSV File App Using Faker.js and objects-to-csv Library Full Tutorial


Welcome folks today in this tutorial we will be building a fake data generator app using node.js and express using a library called as faker.js and objects-tocsv All the source code of the application is given below. A step by step youtube video is also shown below.




Live Demo



Get Started


In order to get started you need to install these dependencies

  1. Express
  2. body-parser
  3. faker
  4. objects-tocsv
  5. fs
  6. ejs


npm i express faker objects-to-csv body-parser ejs


Source Code


First of all you need to create your index.js file which is the starting point of the application and copy paste the full below code to it


const express = require('express')

const objectstocsv = require('objects-to-csv')

const fs = require("fs")

const app = express()

const faker = require('faker')

const bodyParser = require('body-parser')

const PORT = process.env.PORT || 5000

app.set("view engine","ejs")


app.get('/',(req,res) => {
})'/',async(req,res) => {

    var data = []

    var number = req.body.number

    for(var i=0;i<number;i++){

    // convert to csv file

    const csv = new objectstocsv(data);
  // Save to file:
  await csv.toDisk('./test.csv');"./test.csv",() => {




app.listen(PORT,() => {
    console.log("app is listening on port 5000")


See also  Build a GraphQL Server CRUD API in Node.js and Express Using Express-GraphQL Library Full Project For Beginners


Now we need to build the template file called as index.ejs which will be located under views folder so make a new folder views inside the root directory of your project.




<!DOCTYPE html>
    <title>Fake Data Generator</title>
      <div class="container">
          <h1 class="text-center">Fake Data Generator</h1>
          <form action="/" method="post">
            <div class="form-group">
                <input type="number" class="form-control" name="number" id="" placeholder="No of Rows" required>
            <div class="form-group">
                <button class="btn btn-danger btn-block">
                    Generate Data
  <script src=""></script>














Leave a Reply