Cron run Nodejs not working

I need to run a sh script send.shas shown below:

node send.js -q 8435924032 >> send.log

If I run it with crontab, */2 * * * * /home/app/send.sh nothing is output.

And there is mail that shows an error caused by the cron process:

ReferenceError: Promise is not defined
    at requestURL (/home/app/getData.js:34:16)
    at Object.getData (/home/app/getData.js:15:18)
    at /home/app/send.js:173:41
    ...

However, it gives me the correct output and NO ERROR when I directly run sh send.sh

Can someone help? I want to run the program every two minutes. I tried PM2, but such a cron function does not work.

0
source share
2 answers

Have you checked the user root node.js version?

Crontab script root , , root node.js node, script.

Promise node.js.

root, root node.js,

$sudo su
$node -v

, node.js script,

console.log(process.versions); //which contains running node version
+1

:

node /<path>/<to>/<file>/send.js -q 8435924032 >> send.log

cd /<path>/<to>/<file>/;
node ./send.js -q 8435924032 >> send.log
0

Source: https://habr.com/ru/post/1661778/


All Articles