var cron = require('node-cron');
cron.schedule('*/10 * * * *', () => {
for(var i = 0; i < datas.length; i++) {
if (datas[i].price > 10 && datas[i].price < 300) {
const transporter = nodemailer.createTransport({
service: "gmail",
auth: {
user: 'dummy@gmail.com',
pass: 'dummycode'
}
});
let mailOptions = {
from: 'dummy@gmail.com',
to: 'dummy@gmail.com',
subject: 'Let's run',
html: `<ul style="list-style:none;">
${myJson} </ul>` .replace(/\}/g, '<br>')
};
transporter.sendMail(mailOptions, function(err, data){
if (err) {
console.log('Error occurs');
} else { console.log('Email sent!');}
});
}
}
});
Hi all, i have this automated script by node-cron, and after lot of research i can't get any solution to stop the cron scheduler if the condition in the if statement is met. Is there any way to deal with this? or another method in js to run the script periodically, and if the condition is met to stop it? Thanks in advance if you have any tips