我一直在做一个项目,当用户单击前端的按钮时,需要启动和停止cron调度程序。基本上,当用户单击按钮时,cron作业就会启动。单击“停止”按钮将停止计时器。事情就这么简单。
为了实现这一点,我向Nodejs/Express后端发出请求,单击该按钮可以触发调度程序的开始/停止功能。端点是这样的:
const cron = require('node-cron');
router.post('/scheduler', async (req, res) => {
// gets the id from the button
const id =
我将nodejs从8更新到10.12,并收到警告消息。
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",
}
用法:
"use strict";
const cron