Menu

PM2 Tutorial: Keep Your Node.js App Running for Good
📰

PM2 Tutorial: Keep Your Node.js App Running for Good

DEV Community: javascript·The Practical Developer·about 18 hours ago
#ywBWYwhO
#devtojavascript#devto#dev#server#order
Reading 0:00
15s threshold

Quick answer

PM2 is a process manager for Node.js: it starts your app in the background, restarts it when it crashes, and keeps it running after you log out. This post runs a small order-status API under PM2 and shows what happens when the same app is started twice on the same port. It fits a small API on one server, not a platform that already manages processes.

The night the API went quiet

You deploy a small Node API, start it, and it works. Then you close the terminal, and the API dies with it. Or the app throws an uncaught error at 3 a.m., and nobody notices until a customer reports a blank page. The first fix that comes to mind is a bigger server, but it is usually neither. What the app needs is a watcher: a process that starts it, keeps it running after you log out, and brings it back when it crashes. That watcher is what this post sets up.

What I would check before using it

My first check is whether the app has to survive on its own. A script I run by hand does not need a process manager.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.