0

this is how to use it according to the docs in node js each * has what it does

cron.schedule('* * * * *', () => {
  console.log('running a task every minute');
});

 # ┌────────────── second (optional)
 # │ ┌──────────── minute
 # │ │ ┌────────── hour
 # │ │ │ ┌──────── day of month
 # │ │ │ │ ┌────── month
 # │ │ │ │ │ ┌──── day of week
 # │ │ │ │ │ │
 # │ │ │ │ │ │
 # * * * * * *

for example i want a mail to be sent every 10 seconds i do something like this

cronJob.schedule('10 * * * * *', () => {
})

how can i get the 10 seconds from my vue component and pass it to my cron job

xander
  • 395
  • 1
  • 10

2 Answers2

0
cron.schedule('*/10 * * * * *', () => {

 // other code goes here 

})

//This will run after every 10 sec

0

To send email from a node-cron script, you'll need the nodemailer npm package. Following that, you must configure your email by importing the package into your node-cron file and specifying the sending details for your message, a transporter, and mailoption:

    var transporter = nodemailer.createTransport({
   service: 'gmail',
    auth: {
           user: 'yoursendingmail',   
          pass:'yoursendingpassword'              
         },
        const mailOptions = { 
                  from: 'xyz@gmail.com', 
                  to: 'abc@gmail.com,          
                  subject: 'sub here',  
                  html: '<p>text here</p>'}
 };)

after, you set up the node-cron like this:

cronJob.schedule('10 * * * * *', () => {
  transporter.sendMail(mailOptions, function (err, info)
    {
      if(err){}
      else{}//can log info here if email is sent
    }
})
4x0t
  • 26
  • 3