node-cron - Deprecation warning: imediateStart is deprecated and will be removed

499 Views Asked by At

I updated nodejs from 8 to 10.12 and receive that warning message.

D:\BitBucket\EA Studio>node index
DEPRECIATION: imediateStart is deprecated and will be removed soon in favor of the options param.
...

package.json

{
  "dependencies": {
    ...
    "node-cron": "^2.0.3",
}

Usage:

"use strict";

const cron = require("node-cron");
cron.schedule("5 * * * *", () => null, false);

Any solutions?

Since I don't use imediateStart in my code, the warning origin must be within the internal code of the node-cron. Do the developers made that to not forget to update their own code? how much better would be to show: "This version of node-cron uses deprecated code. Please update it to version xxx as soon as it is released".

2

There are 2 best solutions below

0
On BEST ANSWER

Just replace

cron.schedule("5 * * * *", () => null, false);

with

cron.schedule("5 * * * *", () => null, {scheduled:false});

From node-cron documentation on schedule method:

options Object: Optional configuration for job scheduling.

Options

scheduled: A boolean to set if the created task is schaduled. Default true;

timezone: The timezone that is used for job scheduling;

1
On

Run the script with --trace-warnings flag. eg.: node --trace-warnings index.js. It will give you a detailed info what causes the warning.