node.js - 使用nodejs每1小时调度一次文件

标签 node.js

我想在 Windows 环境中使用 node.js 每 1 小时运行一次打印语句。我使用包 node-schedule。

但是当我尝试运行它时,输出并不像预期的那样。我认为我的日程安排格式有误。

所以我尝试了下面的代码:

var schedule = require('node-schedule');

var j = schedule.scheduleJob('*/1 * * *', function(){
    console.log('The answer to life, the universe, and everything!');
});

最佳答案

var schedule = require('node-schedule');
var j = schedule.scheduleJob('* 1 * * *', function(){  // this for one hour
console.log('The answer to life, the universe, and everything!');
});

The cron format consists of:

*    *    *    *    *    *
┬    ┬    ┬    ┬    ┬    ┬
│    │    │    │    │    |
│    │    │    │    │    └ day of week (0 - 7) (0 or 7 is Sun)
│    │    │    │    └───── month (1 - 12)
│    │    │    └────────── day of month (1 - 31)
│    │    └─────────────── hour (0 - 23)
│    └──────────────────── minute (0 - 59)
└───────────────────────── second (0 - 59, OPTIONAL)

这是链接:https://github.com/node-schedule/node-schedule

关于node.js - 使用nodejs每1小时调度一次文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34735908/

相关文章:

javascript - 如何修复 spawn ENAMETOOLONG 错误 nrwl nx 工作区

node.js - Telegram Bot |检测用户是否从移动设备或桌面设备发送消息

javascript - 如果结果返回,如何在 postman 中验证而不考虑结果数量

node.js - ENOENT 在 Express Endpoint 上没有用于 readFileSync 的此类文件

javascript - 当响应长度超过 16101 时,Node Js HTTP 响应崩溃

.net - Node.js 与 .Net 性能

node.js - 与服务器的 Socket.io 连接有时不起作用

node.js - npm 串行连接未安装

node.js - 为什么我的应用程序不能在 Heroku 上建立 websocket 连接?

javascript - 使用 Express.js 从 Angular.js 下载文件