I have developed a REST API in NodeJS and I need to automate the call to a method that retrieves the information from another API (a third party) every minute to insert it into my back-end .
My OS is Centos 6.9. I have read in some posts that it is possible to use cron to automate tasks, but I don't know if it is possible to carry out this task from NodeJS in the back-end itself .
Is there a way to do it from NodeJS ?
Thanks greetings
Better than using
setInterval
is to create a cron.Example
For this example I have used the cron package . You can see about the cron syntax at this link .
If you have a function let's say helloWorld() and you want to automate its call, I think you could use this way of doing it:
What this would do is while you have the app up on the server, every 30000 ms it will make a call to the function that you pass to it as a parameter.