← Back to Blog
Best Practices

How to Keep Your Node.js App Running Forever

Remoud Team · 6 min read · 2026-02-23

A single unhandled JavaScript error can crash an entire Node.js server, taking down the application for all users simultaneously. Here's how to ensure your server stays resilient and online.

1. Catch Unhandled Promise Rejections

In modern Node versions, unhandled promise rejections cause the process to exit completely. Add a safety net listener at the top of your `server.js` file:

process.on('unhandledRejection', (err) => {
  console.error('Unhandled Rejection:', err);
  // Optional: gracefully shut down dependencies if severe
});

2. VPS Deployment: Use PM2

If you deploy to a raw VPS (Ubuntu, DigitalOcean droplet), you cannot just run `node app.js`, as it will die when you close the SSH terminal. You must use a process manager like PM2, which automatically restarts scripts upon crash.

npm intall -g pm2
pm2 start app.js --name "my-app"
pm2 save

3. Cloud PaaS Deployment (The Safer Way)

The safest and easiest modern approach is avoiding raw VPS instances entirely and using a Docker container environment. Providers like Remoud run your Node.js app inside an isolated container.

If Node crashes due to a bad memory leak or error, the container manager detects the process failure and restarts the entire container instantly—much safer and cleaner than PM2 on a dirty server state.

Tired of Server Management?

Deploy your Node.js APIs to Remoud and let us handle process management, load balancing, and SSL.

Start deploying for free →