Overview
Now you will learn how we create resilient services without interrupting the main SSH connection or without the need to create N SSH connections with N open terminals while developing our services in our remote development environment.
Summary
Requirements
- Node.js
- NPM
What is PM2?
PM2 is a daemon process manager that will help you manage and keep your application online 24/7
The services running through it become resilient. A similar analogy is comparing PM2 with NGINX
Installing PM2
npm i -g pm2
Persisting Processes
# Explanation: pm2 start <package-manager> --name <app-name> -- <script-name>
pm2 start pnpm --name woovi-front -- woovi
Your server is launched in daemon mode, meaning it runs as a detached background process.
Under the hood, PM2 spawns a new process for your service that is independent of the initial terminal session.
This decoupling ensures that the server continues to run even if you close the terminal, while PM2 monitors, logs, and automatically restarts the process if it encounters any issues.
Check Processes
pm2 ls
You can view the daemon processes that PM2 spawns for your services, and check the following information
If the status is "online", your service already be up, then you can test using the command curl
I already know that my service may be running on port 3000, you must change the port to your application's port
# use this for test in your VPS
curl http://localhost:3000
# or this, if want to test in the machine host
curl http://yourmachineip:3000
PM2 is powerful when it comes to process management it has many other commands like pm2 delete
to delete an unused daemon process, pm2 restart
to restart a process, and pm2 stop
to end a process execution
In Conclusion
Integrating PM2 into remote development environments is an effective strategy to ensure that your services or applications remain running continuously and stably so that you can move freely without worrying about tying up the main process of your SSH connection and ending up interrupting the service at some point.
Top comments (0)