Menu

1 / 2

Zero-Downtime Deployments for a React + Node App

DEV Community·Sohana Akbar·6 months ago
#TLpEuI2f
#build#terminal#devops#node#reload
Reading 0:00
15s threshold

Deploying a new version of your app without kicking users out or causing errors sounds like a dream, right? Let's make it real.

The Problem

You git push, run your build, restart the server... and for 5–30 seconds, your users see:

Cannot GET /

502 Bad Gateway

Or just a blank white screen of sadness

That's downtime. In 2025, it's not acceptable.

The Setup

We'll assume:

Frontend: React (built with Vite or CRA)

Backend: Node.js + Express

Server: Linux (Ubuntu)

Process manager: PM2

The Strategy

The goal: Old version keeps running until new version is ready.

Here's the plan:

Build the new React bundle

Prepare the new Node backend

Switch traffic atomically

Handle in-flight requests gracefully

Step 1: Build in a Staging Directory

Don't overwrite your live files directly.

bash

Clone fresh or pull latest

git pull origin main

Build frontend to a timestamped folder

TIMESTAMP=$(date +%s)

npm run build -- --dest /var/www/builds/$TIMESTAMP

Copy backend files to a versioned folder

cp -r backend…

Continue reading — create a free account

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