It's been a while since I used node and express and I was sure that this was possible, but i'm having an issue of figuring it out now.
I have a simple postgres database with sequelize. I am building a back end and don't have a populated database yet. I want to be able to provide fake data to use to build the front end and to test with. Is there a way to populate a database when the node server is started? Maybe by reading a json file into the database?
I know that I could point to this fake data using a setting in the environment file, but I don't see how to read in the data on startup. Is there a way to create a local database, read in the data, and point to that?
CodePudding user response:
You can use fake factory package, I think it can solve your problem. https://www.npmjs.com/package/faker-factory
CodePudding user response:
FakerJs provides that solution.
import { faker } from '@faker-js/faker';
const randomName = faker.name.findName();
const randomEmail = faker.internet.email();
with the above, you can run a loop for loop to be specific to create the desired data you may need for your project. Also, check on the free web-API that provides fake or real data to workon