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!
js App in Development Mode with PM2. At this point, your server will auto-restart each time you create, modify or delete a source file in your project. It also works when you add or remove a dependency with npm or yarn .
PM2 allows to reload (auto fallback to restart if not in cluster) an application based on a memory limit/ Please note that the PM2 internal worker (which checks memory), starts every 30 seconds, so you may have to wait a bit before your process gets restarted automatically after reaching the memory threshold.
Run Pm2 using this script
pm2 start node <start script> --restart-delay <time in milliseconds>
Rewrite your client to make several connection attempts. It is always a good thing to do, and it'll also help in this case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With