1

I need to do a assignment and my assignment is to extract fresh WHOIS records database of daily registering domains, which should consist of the name, domain name, email ID, and phone number, and be auto-emailed via cron on a daily basis.

My code is :

import whois from 'whois'
import schedule from 'node-schedule'
import pandas from 'pandas'
import smtp from 'smtp'


const job = schedule.scheduleJob('0 10 * * *', () => {
    const domains = whois.getRegisteredDomains();
  
    const filteredDomains = domains.filter((domain) => {
      return domain.registeredDate >= new Date();
    });
  
    const df = pandas.DataFrame(filteredDomains);
    df.to_csv('domains.csv');
  
    const mailOptions = {
      from: 'mpainkra7@gmail.com',
      to: 'tuktukpainkra7@gmail.com',
      subject: 'New Domains',
      text: filteredDomains
    };
    smtp.sendMail(mailOptions);
  });

  console.log(job)
  
  job.start();

and the error im getting is TypeError: job.start is not a function

I tried looking the error online but I didn't find anything related to it.

  • Are you sure `schedule.Job()` returned something? – tadman Jul 22 '23 at 17:58
  • @tadman line 26... the last line – Mayank Painkra Jul 22 '23 at 17:58
  • yup it is returning – Mayank Painkra Jul 22 '23 at 18:01
  • Your error says otherwise. It's clearly `undefined` at that point. Is this involving TypeScript? If so, it should hint at what return type it's expecting. – tadman Jul 22 '23 at 18:01
  • @tadman sorry .. i did a mistake while copying the code here let me change – Mayank Painkra Jul 22 '23 at 18:03
  • The [documentation](https://www.npmjs.com/package/node-schedule) suggests using `schedule.scheduleJob` instead of `Job`, which could be part of the problem here. Secondly, there's no `start()` required. I'm not even sure `start()` is a thing, unless you can find some documentation for it. – tadman Jul 22 '23 at 18:03
  • @tadman I wrote this code from Google Bard... and it says "the schedule documentation does not mention the start() method. This is because the start() method is a property of the Job object, not the schedule object." – Mayank Painkra Jul 22 '23 at 18:10
  • If you're asking a code generator for code, you'll get code, but it will often *make up things that do not exist* but look good and feel right. This is why you'll need to very carefully vet *any* code it writes. In many cases it makes *code shaped output* that is not actually useful. – tadman Jul 22 '23 at 18:11

0 Answers0