-1

I want to restart nodemon server app.js programmatically every 20 minutes with restart.js.

I'm starting with nodemon -r esm app.js . and server.js should relaunch it somehow.

I tried with pm2 and forever various combinations I don't even remember since none of them worked.

Mikheil misha
  • 51
  • 1
  • 6
  • 2
    Ok. But why? Where are you hosting and what are you trying to solve? – Phix Dec 04 '20 at 05:12
  • They are hosted at the same localhost. There are too many requests from various servers and so far best solution is to just restart – Mikheil misha Dec 04 '20 at 05:16
  • 2
    Nodemon is basically a tool that one uses to restart when the code changes. If it's crashing that's not a good sign, something like pm2 can keep the server up, but it smells like there's another issue here – Phix Dec 04 '20 at 05:39

1 Answers1

0

You can use forever-monitor and setInterval to terminate the child and create a new one each X time you want.

Or Assayag
  • 5,662
  • 13
  • 57
  • 93
  • Accoding to the linked page, "*By default, nodemon waits for one second to restart the process when a file changes, but with the `--delay` switch, you can specify a different delay.*". This is not what the OP is looking for. – Bergi Dec 04 '20 at 14:27
  • Updated my answer. – Or Assayag Dec 04 '20 at 16:36
  • 1
    Since it's completely different, I would've kept the old one deleted and just posted a separate, second answer. Anyway, removed my downvote :-) – Bergi Dec 04 '20 at 17:04
  • I can't post 2 answers in 1 question :) – Or Assayag Dec 04 '20 at 18:50
  • 1
    Yes, you can! For cases such as this, there's [an "*Add another answer*" button](https://meta.stackoverflow.com/q/255359/1048572) at the bottom. I don't think it has a reputation threshold. – Bergi Dec 04 '20 at 20:42