There is literally no tutorial about using Heroku Scheduler with Node.js. Assume that I have a function called sayHello() and I would like to run it every 10 mins. How can I use it in controller. In ruby you write rake function_name() however no explanation made for Node. Can I write ‘/sayHello’ or I should do extra configuration?
There is literally no tutorial about using Heroku Scheduler with Node.js. Assume that I
Share
Create the file
<project_root>/bin/say_hello:Deploy to Heroku and test it with
$ heroku run say_hellothen add it to the scheduler with task namesay_hello.Explanation
Take
say_hello.jsas an example of a Node.js script that you would normally run using$ node say_hello.js.Turn it into a script by
.jsending#! /app/bin/node[1][2]bindirectory [3][1] Read about the shebang on Wikipedia.
[2] The
nodeexecutable is installed inapp/bin/nodeon Heroku. You can check it out by logging into bash on Heroku with$ heroku run bashthen asking$ which node.[3] Heroku requires scripts to be placed in the
bindirectory. See Defining Tasks in the Heroku Dev Center.I agree that the Heroku documentation for scheduling tasks is not very clear for anything other than Ruby scripts. I managed to work it out after some trial and error.