嗨,我是 Node.js 的初学者。我需要使用 cron 向用户发送有关待付款的邮件。我正在使用模块Cron 。 url /remainder 执行完成这项工作所需的所有功能,并且工作得很好。我的疑问是我可以在 cron 作业中调用这个 url 吗?我们如何使用请求/响应。当 cron 运行时,输出为 null 。
var CronJob = require('cron').CronJob;
new CronJob('00 * 23 * * *', function(req,res){
console.log(req);
}, null, true, "America/Los_Angeles");
最佳答案
那么 /remainder
正在做实际的工作吗?只需在回调中调用它即可。
var request = require('request')
var CronJob = require('cron').CronJob;
new CronJob('* * * * * *', function() {
console.log('You will see this message every second');
request('http://www.google.com', function(error, response, body) {
if (!error && response.statusCode == 200) {
console.log('im ok')
// console.log(body) // Show the HTML for the Google homepage.
}
})
}, null, true, "America/Los_Angeles");
关于node.js - 如何在 Node cron 作业中使用请求/响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33340258/