mricardi Posted November 6, 2024 Posted November 6, 2024 Hey guys! I was developing a script in nodejs. It’s a simple one that just gets info from an external API and inserts it into a database. My idea is to run this script once per day. I tried to set up a scheduled task to run "node myscript.js" but I saw that I don't have permissions to run nodejs from a scheduled task. So my question is, is there a way to execute a nodejs script from a scheduled task, or should I look for another way? Quote
wolstech Posted November 6, 2024 Posted November 6, 2024 Scheduled tasks are jailed to your home folder, so they cannot see the node binaries. The easiest solution is to make a web endpoint that can be called to trigger it (e.g. https://domain.heliohost.us/api/cron), and have the task call it using the fetch URL option to trigger it. Not sure how this would be done in Node specifically, but this is the typical solution used for other languages like PHP. You may need a separate subdomain for it if its a separate application. 1 Quote
mricardi Posted November 6, 2024 Author Posted November 6, 2024 Good! I will try it thanks a lot! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.