Full Stack LAMP - MEAN Developer, Python developer. Certified Azure Developer. Freelance programmer/consultant/trainer.

How to insert initial dummy data using Sequelize seeds/Faker

This post is an extension of my previous post, Build a RESTful API Using Node, Express, and Sequelize. From the previous post, you can learn and set up your restful APIs. In this post, I would like to show creating or inserting dummy data using Sequelize seeds/Faker library.

Let’s install Faker:

npm install --save-dev @faker-js/faker

You will get similar output in the console

Now generate a seed file for the todos table using the Sequelize CLI seed generate command as shown below.

sequelize seed:generate --name todos

You will get similar output in the console

Now update generated seed file with the below code.

'use strict';
const { faker } = require('@faker-js/faker');

const todos = [...Array(100)].map((todo) => (
    title: faker.lorem.words(),
    description: faker.lorem.text(),
    createdAt: new Date(),
    updatedAt: new Date()

/** @type {import('sequelize-cli').Migration} */
module.exports = {
  async up (queryInterface, Sequelize) {
      await queryInterface.bulkInsert('todos', todos, {});

  async down (queryInterface, Sequelize) {
     await queryInterface.bulkDelete('todos', null, {});

Run Seeders

Run seeds mean running SQL command to insert data provided in seeder files. You can run specific seed files or you can all seeds as shown below.

sequelize db:seed:all

You will get similar output in the console

Now you can check your database, you will find 100 fake records as configured in the code.

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments