why are my email domains all undefined? const puppeteer = require('puppeteer'); const fs…
- User
why are my email domains all undefined? const puppeteer = require('puppeteer'); const fs = require('fs'); const readline = require('readline'); const cluster = require('cluster');
const emails = []; const emailType = 'rand'; // Either read from emails.txt (list) or randomly generated (rand) const emailAmm = 100; // Only matters if rand is chosen const threads = 8; // Number of threads/instances to run
const emailDomains = [ 'outlook.com', 'gmail.com', 'yahoo.com', 'hotmail.com', 'aol.com', 'icloud.com', 'mail.com', 'msn.com', 'live.com', 'mail.ru', 'sharklasers.com', 'cock.email', '123webmail.net' ];
if (emailType === 'list') { const filePath = 'path/to/emails.txt'; // Specify the path to the emails.txt file const fileStream = fs.createReadStream(filePath);
const rl = readline.createInterface({ input: fileStream, output: process.stdout, console: false }); rl.on('line', function (line) { emails.push(line); }); rl.on('close', function () { startSubscribing(emails); });} else if (emailType === 'rand') { for (let i = 0; i < emailAmm; i++) { const email = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15) + emailDomains[Math.random(0, emailDomains.length)]; emails.push(email); }
startSubscribing(emails);}
- Assistant
Based on the code provided, the email domains are all undefined because the
Math.random(0, emailDomains.length)method does not exist. TheMath.random()method generates a random number between 0 and 1, but it does not take any arguments. To fix this issue, you should useMath.floor(Math.random() * emailDomains.length)to generate a random index for selecting an email domain from theemailDomainsarray. Here's the updated code snippet:if (emailType === 'list') { // ... } else if (emailType === 'rand') { for (let i = 0; i < emailAmm; i++) { const email = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15) + emailDomains[Math.floor(Math.random() * emailDomains.length)]; // Use Math.floor(Math.random() * emailDomains.length) emails.push(email); } startSubscribing(emails); }This will ensure that a random email domain is selected from the
emailDomainsarray for each generated email.