Skip to content

Instantly share code, notes, and snippets.

@Angel-Martinez-G-6085
Created June 10, 2025 04:38
Show Gist options
  • Save Angel-Martinez-G-6085/d725e42ae2505829893c44051f66daad to your computer and use it in GitHub Desktop.
Save Angel-Martinez-G-6085/d725e42ae2505829893c44051f66daad to your computer and use it in GitHub Desktop.
Script que crea un archivo csv usando el api faker para generar datos falsos
import { faker } from '@faker-js/faker';
import { json2csv } from 'json-2-csv';
import {writeFileSync} from 'fs'
async function convertir(data) {
try {
const csv = await json2csv(data);
writeFileSync('datos.csv', csv);
console.log('Archivo CSV creado exitosamente');
} catch (err) {
console.error(err);
}
}
const infoArray = [];
for (let index = 0; index < 200; index++) {
const lead = {
id: Math.floor(Math.random() * 10000),
name: faker.person.fullName(),
email: faker.internet.email(),
company: faker.company.name(),
phone: faker.phone.number(),
industry: faker.helpers.arrayElement(['Technology', 'Healthcare', 'Finance', 'Education', 'Retail']),
employees: faker.helpers.arrayElement(['1-10', '11-50', '51-200', '201-1000', '1000+']),
job_title: faker.person.jobTitle(),
website: faker.internet.url(),
source: faker.helpers.arrayElement(['LinkedIn', 'Google Ads', 'Content Download', 'Webinar', 'Referral'])
};
infoArray.push(lead)
}
convertir(infoArray)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment