Node.js pm2 delay script launch

javascript, node.js, pm2

Solution

Rewrite your client to make several connection attempts. It is always a good thing to do, and it'll also help in this case.

Problem

I use the awesome pm2 package to keep my node.js apps alive, but i have an issue I don't know how to fix. One of my apps requires several scripts, a server and a few clients. Often when I restart my server, all the script are restarted, but connection isn't established because the clients have loaded before the server. Is it possible to make sure that a script starts after the other have loaded? Let me try to rephrase so it gets clearer I have : ``` pm2 start server.js pm2 start client.js ``` And I'd like to somehow start the client only when the server is started. Apologies is my question seems unclear, please comment and I'll explain more!

Original source