0

I am trying to run a node script with cron every minute. I dont believe it is running at all. When I run grep cron /var/log/syslog I dont see it running in the log.

Did I write the cron job wrong? If so how do I run a node script in a cron job?

 * * * * * node /home/ubuntu/Server/nodeScript.js

2 Answers 2

4

Cron jobs don't run in a shell so you have to give the full path to the node binary.

/usr/bin/node (or whatever it is on that machine)

Try which node to find out

Sign up to request clarification or add additional context in comments.

Comments

0

The easiest way to run it every single minute is just to put your code in endless loop with timeout.

For example

function yourCode () {
    for {
        // your code
        timeout(60 * 1000)
    }
}
function timeout(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
}

Just be sure you run it with pm2 or supervisor so when it crashes it can restart automatically.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.