Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

node-schedule is not work at time

Tags:

node.js

i want to use node-schedule , i get information from Data Base every day , and for each item i want to do some thing at special time. this is my code :

users.forEach(function(users_entry){
                                if(err){
                                    console.log(err);
                                }
                                else{
                                   var date = new Date(2014, 11, 29, 11, 45, 0);
                                   schedule.scheduleJob(date,
                                   function(){
                                      console.log('The world is going to end today.');
                                   });
                                 }
                          });

but above code doesn't run at mentioned time and works all the time. what is problem?

like image 224
Hediyeh Avatar asked Nov 29 '14 07:11

Hediyeh


People also ask

How does node schedule work?

Node Schedule is a flexible cron-like and not-cron-like job scheduler for Node. js. It allows you to schedule jobs (arbitrary functions) for execution at specific dates, with optional recurrence rules. It only uses a single timer at any given time (rather than reevaluating upcoming jobs every second/minute).

How do I schedule a task in node?

Scheduling a Simple Task with node-cron Input the following code into the index. js file to create our simple task scheduler: const cron = require("node-cron"); const express = require("express"); const app = express(); cron. schedule("*/15 * * * * *", function () { console.

What is node-Cron?

The node-cron module is tiny task scheduler in pure JavaScript for node. js based on GNU crontab. This module allows you to schedule task in node. js using full crontab syntax.


1 Answers

i changed my code and used cron. https://www.npmjs.org/package/cron

it works very well :)

var CronJob = require('cron').CronJob;
new CronJob('* * * * * *', function(){
    console.log('You will see this message every second');
}, null, true, "America/Los_Angeles");
like image 175
Hediyeh Avatar answered Nov 15 '22 11:11

Hediyeh