i have a node(v0.7.3-pre) server with node-cron(0.3.2) and node-time(0.8.2):
var cronJob = require('cron').CronJob;
var cronJ = new cronJob({
cronTime: "00 29 16 6 * *",
onTick: function() {
console.log("Tick");
},
start:true,
timeZone: "America/Los_Angeles"
});
console.log(cronJ);
it runs, but the Cron is allways working with the server time(UTC), and the returned cron is:
{ _callbacks: [ [Function] ],
onComplete: undefined,
cronTime:
{ source: '00 29 16 6 * *',
zone: undefined,
second: { '0': true },
minute: { '29': true },
hour: { '16': true },
dayOfWeek:
...
the zone
is set as undefined
, am i missing something?
Thankfully, you can configure a specific timezone for your Cron job as follows: First, you need to export the TZ variable in your Shell script before any other Shell entries. Next, access your crontab and use the crontab environment variable CRON_TZ at the start of the crontab file.
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.
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.
Because an error in node-cron module. I already send a pull request that will fix it. You can change this lines in your local copy of this module.
You also can use several function parameters to initialize cronJob instead of one object:
var cronJob = require('cron').CronJob;
var cronJ = new cronJob("00 29 16 6 * *", function() {
console.log("Tick");
}, undefined, true, "America/Los_Angeles");
console.log(cronJ);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With