Comparing version
{ | ||
"name": "node-cron", | ||
"version": "3.0.3", | ||
"version": "4.0.0-beta.1", | ||
"description": "A simple cron-like task scheduler for Node.js", | ||
@@ -8,7 +8,17 @@ "author": "Lucas Merencia", | ||
"homepage": "https://github.com/merencia/node-cron", | ||
"main": "src/node-cron.js", | ||
"main": "node-cron", | ||
"types": "./dist/node-cron.d.ts", | ||
"type": "commonjs", | ||
"exports": { | ||
".": { | ||
"import": "./node-cron.mjs", | ||
"require": "./node-cron.cjs" | ||
} | ||
}, | ||
"scripts": { | ||
"test": "nyc --reporter=html --reporter=text mocha --recursive", | ||
"lint": "./node_modules/.bin/eslint ./src ./test", | ||
"check": "npm run lint && npm test" | ||
"test": "c8 --reporter text --reporter=lcov --exclude '**/*.test.ts' mocha --recursive './src/**/*.test.ts'", | ||
"lint": "./node_modules/.bin/eslint ./src", | ||
"check": "npm run lint && npm test", | ||
"build": "tsc", | ||
"prepublishOnly": "npm run build" | ||
}, | ||
@@ -32,14 +42,32 @@ "engines": { | ||
}, | ||
"dependencies": { | ||
"uuid": "8.3.2" | ||
"devDependencies": { | ||
"@eslint/js": "^9.25.1", | ||
"@tsconfig/recommended": "^1.0.8", | ||
"@types/chai": "^5.2.1", | ||
"@types/expect": "^1.20.4", | ||
"@types/mocha": "^10.0.10", | ||
"@types/node": "^22.15.3", | ||
"@types/sinon": "^17.0.4", | ||
"c8": "^10.1.3", | ||
"chai": "^5.2.0", | ||
"eslint": "^9.25.1", | ||
"eslint-plugin-mocha": "^10.5.0", | ||
"eslint-plugin-node": "^11.1.0", | ||
"globals": "^16.0.0", | ||
"mocha": "^11.1.0", | ||
"sinon": "^20.0.0", | ||
"tsup": "^8.4.0", | ||
"tsx": "^4.19.3", | ||
"typescript": "^5.8.3", | ||
"typescript-eslint": "^8.31.0" | ||
}, | ||
"devDependencies": { | ||
"chai": "^4.2.0", | ||
"eslint": "^5.7.0", | ||
"istanbul": "^0.4.2", | ||
"mocha": "^6.1.4", | ||
"moment-timezone": "^0.5.33", | ||
"nyc": "^14.0.0", | ||
"sinon": "^7.3.2" | ||
"c8": { | ||
"reporter": [ | ||
"html", | ||
"text" | ||
], | ||
"exclude": [ | ||
"src/test-assets/**" | ||
] | ||
} | ||
} |
123
README.md
@@ -5,17 +5,8 @@ # Node Cron | ||
[](https://img.shields.io/npm/v/node-cron.svg) | ||
[](https://coveralls.io/github/node-cron/node-cron?branch=master) | ||
[](https://codeclimate.com/github/merencia/node-cron) | ||
[](https://travis-ci.org/merencia/node-cron) | ||
[](https://david-dm.org/merencia/node-cron) | ||
[](https://david-dm.org/merencia/node-cron#info=devDependencies) | ||
[](#backers) | ||
[](#sponsors) | ||
 | ||
[](https://coveralls.io/github/node-cron/node-cron?branch=main) | ||
[](https://libraries.io/npm/node-cron) | ||
The node-cron module is tiny task scheduler in pure JavaScript for node.js based on [GNU crontab](https://www.gnu.org/software/mcron/manual/html_node/Crontab-file.html). This module allows you to schedule task in node.js using full crontab syntax. | ||
**Need a job scheduler with support for worker threads and cron syntax?** Try out the [Bree](https://github.com/breejs/bree) job scheduler! | ||
[](https://nodei.co/npm/node-cron/) | ||
## Getting Started | ||
@@ -31,4 +22,6 @@ | ||
- commonjs | ||
```javascript | ||
var cron = require('node-cron'); | ||
const cron = require('node-cron'); | ||
@@ -40,2 +33,12 @@ cron.schedule('* * * * *', () => { | ||
- es6 (module) | ||
```javascript | ||
import cron from 'node-cron'; | ||
cron.schedule('* * * * *', () => { | ||
console.log('running a task every minute'); | ||
}); | ||
``` | ||
## Cron Syntax | ||
@@ -61,12 +64,11 @@ | ||
| field | value | | ||
|--------------|---------------------| | ||
| second | 0-59 | | ||
| minute | 0-59 | | ||
| hour | 0-23 | | ||
| day of month | 1-31 | | ||
| month | 1-12 (or names) | | ||
| day of week | 0-7 (or names, 0 or 7 are sunday) | | ||
| field | value | | ||
| ------------ | --------------------------------- | | ||
| second | 0-59 | | ||
| minute | 0-59 | | ||
| hour | 0-23 | | ||
| day of month | 1-31 | | ||
| month | 1-12 (or names) | | ||
| day of week | 0-7 (or names, 0 or 7 are sunday) | | ||
#### Using multiples values | ||
@@ -77,3 +79,3 @@ | ||
```javascript | ||
var cron = require('node-cron'); | ||
import cron from 'node-cron'; | ||
@@ -90,3 +92,3 @@ cron.schedule('1,2,4,5 * * * *', () => { | ||
```javascript | ||
var cron = require('node-cron'); | ||
import cron from 'node-cron'; | ||
@@ -100,10 +102,16 @@ cron.schedule('1-5 * * * *', () => { | ||
Step values can be used in conjunction with ranges, following a range with '/' and a number. e.g: `1-10/2` that is the same as `2,4,6,8,10`. Steps are also permitted after an asterisk, so if you want to say “every two minutes”, just use `*/2`. | ||
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 | ||
var cron = require('node-cron'); | ||
import cron from 'node-cron'; | ||
cron.schedule('*/2 * * * *', () => { | ||
console.log('running a task every two minutes'); | ||
console.log('running a task every even minute'); | ||
}); | ||
cron.schedule('1-59/2 * * * *', () => { | ||
console.log('running a task every odd minute'); | ||
}); | ||
``` | ||
@@ -116,3 +124,3 @@ | ||
```javascript | ||
var cron = require('node-cron'); | ||
import cron from 'node-cron'; | ||
@@ -127,3 +135,3 @@ cron.schedule('* * * January,September Sunday', () => { | ||
```javascript | ||
var cron = require('node-cron'); | ||
import cron from 'node-cron'; | ||
@@ -150,2 +158,3 @@ cron.schedule('* * * Jan,Sep Sun', () => { | ||
- **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`. | ||
@@ -156,3 +165,3 @@ | ||
```js | ||
var cron = require('node-cron'); | ||
import cron from 'node-cron'; | ||
@@ -167,3 +176,3 @@ cron.schedule('0 1 * * *', () => { | ||
## ScheduledTask methods | ||
## BasicScheduledTask methods | ||
@@ -175,5 +184,5 @@ ### Start | ||
```javascript | ||
var cron = require('node-cron'); | ||
import cron from 'node-cron'; | ||
var task = cron.schedule('* * * * *', () => { | ||
const task = cron.schedule('* * * * *', () => { | ||
console.log('stopped task'); | ||
@@ -192,5 +201,5 @@ }, { | ||
```javascript | ||
var cron = require('node-cron'); | ||
import cron from 'node-cron'; | ||
var task = cron.schedule('* * * * *', () => { | ||
const task = cron.schedule('* * * * *', () => { | ||
console.log('will execute every minute until stopped'); | ||
@@ -207,8 +216,37 @@ }); | ||
```javascript | ||
var cron = require('node-cron'); | ||
import cron from 'node-cron'; | ||
var valid = cron.validate('59 * * * *'); | ||
var invalid = cron.validate('60 * * * *'); | ||
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 | ||
@@ -222,5 +260,5 @@ | ||
- Fork the repo on GitHub; | ||
- Commit changes to a branch in your fork; | ||
- Pull request "upstream" with your changes; | ||
- Fork the repo on GitHub; | ||
- Commit changes to a branch in your fork; | ||
- Pull request "upstream" with your changes; | ||
@@ -243,3 +281,2 @@ NOTE: Be sure to merge the latest from "upstream" before making a pull request! | ||
## Sponsors | ||
@@ -260,6 +297,4 @@ | ||
## License | ||
node-cron is under [ISC License](https://github.com/merencia/node-cron/blob/master/LICENSE.md). |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
140417
105.38%0
-100%62
40.91%3346
125.62%283
14.11%0
-100%19
171.43%1
Infinity%- Removed
- Removed