admin管理员组

文章数量:1417096

I am Using Nodejs, and want trigger one function on 5:30 AM, 11:30 PM daily.

How should i follow that approach.

I also want to add more time apart from above like 9:45 PM, 5:30 PM

I have check tried but not getting any luck.

var j = schedule.scheduleJob('* * * 23 07 00', function () {
    console.log('The answer to life, the universe, and everything!');
});
j.schedule()

Thanks.

I am Using Nodejs, and want trigger one function on 5:30 AM, 11:30 PM daily.

How should i follow that approach.

I also want to add more time apart from above like 9:45 PM, 5:30 PM

I have check https://www.npmjs./package/node-schedule tried but not getting any luck.

var j = schedule.scheduleJob('* * * 23 07 00', function () {
    console.log('The answer to life, the universe, and everything!');
});
j.schedule()

Thanks.

Share Improve this question edited Apr 22, 2019 at 17:39 Nikhil Savaliya asked Apr 22, 2019 at 17:35 Nikhil SavaliyaNikhil Savaliya 2,1664 gold badges26 silver badges45 bronze badges 5
  • 1 I doubt it's a matter of luck, give a minimal reproducible example. – jonrsharpe Commented Apr 22, 2019 at 17:37
  • 1 tried but not getting any luck.....that modules has 164,708 weekly downloads. It has nothing to do with luck, you're just doing something wrong. If you want an actual answer you're gonna have to be more specific – Isaac Vidrine Commented Apr 22, 2019 at 17:39
  • 1 Hello Nikhil, I've voted to close your question as too broad. Please ask a more specific question, ideally including some of your code. See How to Ask – Patrick Hund Commented Apr 22, 2019 at 17:39
  • 1 Great! Now whats the problem?Saying Not having any luck tells us nothing. – Isaac Vidrine Commented Apr 22, 2019 at 17:41
  • not sure how to trigger functions based on above time like * * * 23 07 00 is 11:07 PM IST, but console didint apeard that time – Nikhil Savaliya Commented Apr 22, 2019 at 17:42
Add a ment  | 

1 Answer 1

Reset to default 5

You have specified a wrong schedule pattern.

More readable way is using objects like this:

const j = schedule.scheduleJob({hour: 5, minute: 30}, () => {
  console.log('Job runs every day at 5:30AM');
});

And in case you need multiple Jobs running at different time of the day - create a few jobs with different time pattern and use the same function in each.

本文标签: javascripttrigger function on specific time daily nodejsStack Overflow