Skip to main content

Creating a Seed Route

Lesson Objectives#

  1. Create a Seed Route

Create a Seed Route#

Sometimes you might need to add data to your database for testing purposes. You can do so like this:

app.get("/fruits/seed", (req, res) => {  Fruit.create(    [      {        name: "grapefruit",        color: "pink",        readyToEat: true,      },      {        name: "grape",        color: "purple",        readyToEat: false,      },      {        name: "avocado",        color: "green",        readyToEat: true,      },    ],    (err, data) => {      res.redirect("/fruits");    }  );});