node.js - 如何在 Node cron 作业中使用请求/响应

标签 node.js cron

嗨,我是 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/

相关文章:

node.js google oauth2 示例停止工作 invalid_grant

javascript - Meteor wrapAsync 没有在客户端返回值

php - 为什么我的 PHP cron 脚本不播放声音?

shell - Cron xdotool 不运行

linux - 我将查询保存在 shell 脚本中的临时文件位置

node.js - Express 和 Node.js 超时

java - 如何创建nodejs xmpp服务器和android xmpp客户端

node.js - Azure 表存储性能

python - 使用 cron 运行脚本在 mac 上不起作用

linux - 为 nodejs 运行 cron 并删除临时文件