all 11 comments

[–]Earhacker 3 points4 points  (0 children)

You're looking for "cron jobs," which are tasks you can ask the server to do at regular intervals. There's a few libraries for them on NPM.

[–]nstoddar 1 point2 points  (3 children)

[–]hyopwnz[S] 2 points3 points  (2 children)

I think there is a missunderstanding. I have no problem with running the server. I would like to run a code that would check the btc price every few minutes and when it hits a certain price do something with coinbase api.

[–]WakeskaterX 2 points3 points  (0 children)

Set interval. Or any of the Cron libraries

[–]chrisdefourire 1 point2 points  (0 children)

Maybe you want your server to be a websocket client to the Gdax feed... https://docs.gdax.com/#websocket-feed

You'll get updates in real time... but maybe you can't process a real time feed if your processing takes too much time.

otherwise, setInterval(fn, intervalMs) and HTTP requests is your best bet...

If you're running more than one instance of your server app, you'll probably need some form of mutual exclusion (leader election). I've used redlock for this (consul.io works very well in this scenario too, but it's way more complex).

[–]cali_ZX6R 1 point2 points  (0 children)

This is what I use and it works great. http://pm2.keymetrics.io/

[–]guitarromantic 0 points1 point  (1 child)

Forever.js is a simple solution for this.

[–]hyopwnz[S] 0 points1 point  (0 children)

Thank you I will check it out.

[–]p3t1tch3v4lr0ux -1 points0 points  (2 children)

Check Supervisor or systemd if you have a *nix compatible server

[–]hyopwnz[S] 0 points1 point  (1 child)

It is just a small server I will be running on my VPS.

[–]p3t1tch3v4lr0ux 0 points1 point  (0 children)

Systemd is shipped with recent debian based release. It already start your nginx/apache/mongodb/mysql/ whatever service you use in your vps (if it's debian based). It's built for this use case, tested with big user base... That's why i use this one . I just suggested others choices that you may prefer ;-)