
Security News
/Research
npm Phishing Email Targets Developers with Typosquatted Domain
A phishing attack targeted developers using a typosquatted npm domain (npnjs.com) to steal credentials via fake login pages - watch out for similar scams.
node-crontab
Advanced tools
A task scheduler for node that uses the crontab syntax
Why node-crontab?
Need to schedule tasks in node and you already have the cron syntax? Then you need node-crontab! We take care of the task scheduling and timing and all you have to do is tell us what to do!
With node-crontab, you can pass in your callback, arguments for the callback, and even the context of the callback function! We also take care of times that are normally too long for setInterval/setTimeout to handle automatically!
So if this sounds like something you need, keep reading!
Setup
All you have to do is run this command in the directory of your node project:
npm install node-crontab
npm will take care of the rest!
Example Usage
Regular job
var crontab = require('node-crontab');
var jobId = crontab.scheduleJob("*/2 * * * *", function(){ //This will call this function every 2 minutes
console.log("It's been 2 minutes!");
});
Arguments
var crontab = require('node-crontab');
var jobId = crontab.scheduleJob("* * * * *", function(a){
console.log("Hello " + a + "! It's been a minute!");
}, ["World"]);
Context
var crontab = require('node-crontab');
var obj = {a: "World"};
var jobId = crontab.scheduleJob("* * * * *", function(){
console.log("Hello " + this.a + "! It's been a minute!");
}, null, obj);
Non-repeating
var crontab = require('node-crontab');
var jobId = crontab.scheduleJob("* * * * *", function(){
console.log("Hello world! It's been a minute, but this will be the only time I run.");
}, null, null, false);
Killing a job
var crontab = require('node-crontab');
var jobId = crontab.scheduleJob("* * * * *", function(){
console.log("It's been a minute!");
});
crontab.cancelJob(jobId); //Should cancel the job immediately
Suicidal jobs
var crontab = require('node-crontab');
var jobId = crontab.scheduleJob("* * * * *", function(){
console.log("It's been a minute, but this is the last time I run.");
crontab.cancelJob(jobId); // Jobs can cancel themselves, too!
});
API
int crontab.scheduleJob(cronTime, callback, [args], [context], [repeating = true])
bool crontab.cancelJob(jobId)
To Do
Wrap-up
Have an issue? Feel free to open an issue in the issues page. If you want to help, feel free to fork and make pull requests!
FAQs
Crontab-based task scheduler for node.
The npm package node-crontab receives a total of 736 weekly downloads. As such, node-crontab popularity was classified as not popular.
We found that node-crontab demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
/Research
A phishing attack targeted developers using a typosquatted npm domain (npnjs.com) to steal credentials via fake login pages - watch out for similar scams.
Security News
Knip hits 500 releases with v5.62.0, refining TypeScript config detection and updating plugins as monthly npm downloads approach 12M.
Security News
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.