I need to generate a JSON file using faker.js that contains information for 25 random users.
My approach involves initializing an empty array, looping through with faker, pushing the generated data into the array, and then saving it to a json file. However, it doesn't seem to be working as expected.
Below is the code snippet:
var faker = require('faker');
var fs = require('fs');
var userArray = [];
for (i=0; i<=25; i++) {
var userData = {};
userData.name = faker.fake("{{name.findName}}");
userData.email = faker.fake("{{internet.email}}");
userArray.push(userData);
};
fs.writeFile('data.json', JSON.stringify(userArray), (err) => {
if (err) throw err;
console.log('File saved successfully!');
});