-1

I apologize if the way I'm asking this is why I haven't found an answer yet, but I've got a simple JS script that makes an AJAX request and gets data from an API and stores it.

I'd like to put that script on a server and have it run every 5 minutes, not client-side, but server-side.

I've found a resource called Later.js but I am not sure how to set it up on a server to automatically initialize and run.

Any help is greatly appreciated!!!

Michael
  • 1
  • 2
  • Server-side JS? What!? I don't think that even exists. You can call php pages with crontab though. – x13 Oct 02 '15 at 23:54
  • Here's the SpiderMonkey site/docs https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey – Michael Oct 03 '15 at 00:04
  • In that case you need to edit your question, a lot. You should ask 'how to execute spidermonkey every x [unit of time]' – x13 Oct 03 '15 at 00:08

1 Answers1

0

It's hard to know without your exact code.

You should be able to do something with jQuery, like:

function foo () {
   //your code here
}
foo(); //run function once on startup
setInterval(foo, 5 * 60 * 1000) //and again every five minutes

Later.js is a cool library for calculating time in milliseconds, but that's all it does. If you have installed and required it via NPM, you could use it like:

var 5min = later.parse.text('every 5 min');
setInterval(foo, 5min);

As you can see, you might as well just use standard JS/jQuery to solve your issue.

Mitch Lillie
  • 2,217
  • 18
  • 25
  • Thanks, Mitch, but I am looking to run this on a server, not client side. I'm looking at SpiderMonkey and Rhino, but I am out of my league in understanding some of the docs. The objective is to run the program on a server and never initialize it client-side, only access the mongoDB that the data is stored into. – Michael Oct 03 '15 at 00:03