silverwind
silverwind

Reputation: 3925

Restart a node process from within itself

Is it possible to restart a running single-threaded node process entirely from within itself?

I imagine the steps to take for a server would be something like this:

Could this work or am I totally wrong?

Upvotes: 1

Views: 2196

Answers (1)

loganfsmyth
loganfsmyth

Reputation: 161467

This is possible, but generally people just use existing solutions that start a single master process and N server processes. Then when a server process dies or stops, it just starts a new one. One example is pm2.

That said, your example sounds correct to me as long as you use the detached: true argument for .spawn

Upvotes: 2

Related Questions