You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

node-cron

Package Overview
Dependencies
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-cron - npm Package Compare versions

Comparing version

to
4.0.0-beta.6

24

dist/node-cron.d.ts

@@ -11,2 +11,7 @@ /**

import { ScheduledTask, TaskFn } from "./tasks/scheduled-task";
export interface NodeCron {
schedule: typeof schedule;
createTask: typeof createTask;
validate: typeof validate;
}
/**

@@ -61,19 +66,8 @@ * Represents the configuration options for a scheduled task.

declare function validate(expression: string): boolean;
export { ScheduledTask } from './tasks/scheduled-task';
export type { TaskFn, TaskContext, TaskOptions } from './tasks/scheduled-task';
declare const nodeCron: NodeCron;
/**
* Default export containing the main functions of the module.
*/
declare const _default: {
/**
* Schedules a task to be executed according to the provided cron expression.
*/
schedule: typeof schedule;
/**
* Creates a task instance based on the provided parameters.
*/
createTask: typeof createTask;
/**
* Validates a cron expression to ensure it follows the correct format.
*/
validate: typeof validate;
};
export default _default;
export default nodeCron;

@@ -117,19 +117,11 @@ "use strict";

}
/**
* Default export containing the main functions of the module.
*/
exports.default = {
/**
* Schedules a task to be executed according to the provided cron expression.
*/
const nodeCron = {
schedule,
/**
* Creates a task instance based on the provided parameters.
*/
createTask,
/**
* Validates a cron expression to ensure it follows the correct format.
*/
validate
};
/**
* Default export containing the main functions of the module.
*/
exports.default = nodeCron;
//# sourceMappingURL=node-cron.js.map
{
"name": "node-cron",
"version": "4.0.0-beta.5",
"version": "4.0.0-beta.6",
"description": "A Lightweight Task Scheduler for Node.js",

@@ -14,3 +14,4 @@ "author": "Lucas Merencia",

"import": "./node-cron.mjs",
"require": "./node-cron.cjs"
"require": "./node-cron.cjs",
"types": "./dist/node-cron.d.ts"
}

@@ -17,0 +18,0 @@ },

@@ -11,2 +11,4 @@ # Node Cron

### [Node-Cron Documentation](http://nodecron.com)
## Getting Started

@@ -71,169 +73,3 @@

#### Using multiples values
You may use multiples values separated by comma:
```javascript
import cron from 'node-cron';
cron.schedule('1,2,4,5 * * * *', () => {
console.log('running every minute 1, 2, 4 and 5');
});
```
#### Using ranges
You may also define a range of values:
```javascript
import cron from 'node-cron';
cron.schedule('1-5 * * * *', () => {
console.log('running every minute to 1 from 5');
});
```
#### Using step values
Step values can be used in conjunction with ranges, following a range with '/' and a number. e.g: `0-10/2` that is the same as `0,2,4,6,8,10`.
Steps are also permitted after an asterisk, so if you want to say “every two minutes”, just use `*/2`.
When setting `1-10/2` it's going to start with 1 and increase by 2, the same as `1,3,5,7,9`.
```javascript
import cron from 'node-cron';
cron.schedule('*/2 * * * *', () => {
console.log('running a task every even minute');
});
cron.schedule('1-59/2 * * * *', () => {
console.log('running a task every odd minute');
});
```
#### Using names
For month and week day you also may use names or short names. e.g:
```javascript
import cron from 'node-cron';
cron.schedule('* * * January,September Sunday', () => {
console.log('running on Sundays of January and September');
});
```
Or with short names:
```javascript
import cron from 'node-cron';
cron.schedule('* * * Jan,Sep Sun', () => {
console.log('running on Sundays of January and September');
});
```
## Cron methods
### Schedule
Schedules given task to be executed whenever the cron expression ticks.
Arguments:
- **expression** `string`: Cron expression
- **function** `Function`: Task to be executed
- **options** `Object`: Optional configuration for job scheduling.
#### Options
- **scheduled**: A `boolean` to set if the created task is scheduled. Default `true`;
- **catchUp**: A `boolean` to set if the created task should be able to recover missed executions. Default `false`;
- **timezone**: The timezone that is used for job scheduling. See [IANA time zone database](https://www.iana.org/time-zones) for valid values, such as `Asia/Shanghai`, `Asia/Kolkata`, `America/Sao_Paulo`.
**Example**:
```js
import cron from 'node-cron';
cron.schedule('0 1 * * *', () => {
console.log('Running a job at 01:00 at America/Sao_Paulo timezone');
}, {
scheduled: true,
timezone: "America/Sao_Paulo"
});
```
## BasicScheduledTask methods
### Start
Starts the scheduled task.
```javascript
import cron from 'node-cron';
const task = cron.schedule('* * * * *', () => {
console.log('stopped task');
}, {
scheduled: false
});
task.start();
```
### Stop
The task won't be executed unless re-started.
```javascript
import cron from 'node-cron';
const task = cron.schedule('* * * * *', () => {
console.log('will execute every minute until stopped');
});
task.stop();
```
### Validate
Validate that the given string is a valid cron expression.
```javascript
import cron from 'node-cron';
const valid = cron.validate('59 * * * *');
const invalid = cron.validate('60 * * * *');
```
### Naming tasks
You can name your tasks to make it easier to identify them in the logs.
```javascript
import cron from 'node-cron';
const task = cron.schedule('* * * * *', () => {
console.log('will execute every minute until stopped');
}, {
name: 'my-task'
});
```
### List tasks
You can list all the tasks that are currently running.
```javascript
import cron from 'node-cron';
const tasks = cron.getTasks();
for (let [key, value] of tasks.entries()) {
console.log("key", key)
console.log("value", value)
}
```
## Issues

@@ -240,0 +76,0 @@

Sorry, the diff of this file is not supported yet