Wednesday, 24 May 2017

How do you get cron job running Node.js script to read variables from .env file?

I've currently got a cron job setup where it runs a Node.js script. The Node.js script uses the dotenv package to read a .env file that has some API keys.

When I run the Node.js script from the command line, the variables are read correctly from the .env file and works with my Node.js script.

But when cron runs the Node.js script, the variables that I'm trying to set return undefined.

00 05 * * * /home/michaellee/.nvm/versions/node/v6.10.0/bin/node /home/michaellee/index.js >> /home/michaellee/output.log

The .env file resides in the same level as the index.js file.

The cron job is set using crontab -e from the user michaellee, the same user that has the files on Ubuntu.



via michaellee

No comments:

Post a Comment