Zero-Downtime Deployments for Node.js Apps in xCloud
Updated November 29, 2026 · 10 min read
A normal Node.js deploy stops your app and starts it again, so visitors can get 502 errors for a moment. With Release mode in xCloud, each release starts next to the live one, and traffic moves to it only when it is healthy.
This guide covers what is specific to Node.js, including PM2 ecosystem files with background workers. Read How to use zero-downtime deployments for the basics. For a Next.js app, keep the start script as next start with no fixed port; see Deploy a Next.js app on xCloud.
Requirements
- A Node.js site deployed from Git on an nginx server. On OpenLiteSpeed the card shows “Release mode is not available for Node.js sites on OpenLiteSpeed servers. It works on nginx servers, so host this site on an nginx server to use it.”
- No
.envfile in the repository. - No PM2 commands in the deploy script, except one line that reloads your root ecosystem file (see Your own ecosystem file).
- If you use a root ecosystem file with workers: the site deployed normally once, so its web app is running.
- The Manage deploy scripts permission to turn Release mode on.
How a Node.js deploy works
For SSR and Hybrid apps:
- xCloud builds the new release in its own folder (install and build).
- It starts the release with your start command, or your ecosystem file, on a second port. The live release keeps running on the first.
- It sends requests to the new release on
127.0.0.1until it answers with a status below 500. The log shows, for example, “Node health check passed on 127.0.0.1:3003 (HTTP 200).” - nginx reloads gracefully and sends new requests to the new release.
- The old process gets 30 seconds to finish the requests it is serving, then xCloud stops it.
If the health check fails, nothing switches and the old process keeps serving. The next deploy uses the other port, so the two ports take turns.
Static builds don’t run a process: the build goes into a new release folder and the site switches to it in one step.
Step 1: Turn Release mode on
Open the site, click Git, and scroll to the Release mode card. On a Node.js site the card also says: “Turn release mode off, change the serving mode, then turn it on again.”

Click the switch and confirm with Turn on.

When it is on, .env is shared between releases.

You can also choose Release mode (zero-downtime deploys) when you create a Node.js site with Deploy via Git; see How to deploy a Node.js application.
Step 2: Make your app ready for two ports
Your app runs on a different port in each release, so it must take the port from the environment:
const port = process.env.PORT || 3000;
const host = process.env.HOST || '127.0.0.1';
const server = app.listen(port, host);
- PORT: xCloud sets it for each release, after loading your
.env, so aPORTin.envdoes not move the release to the other port. - .env loaders: if your app loads
.envwith env-cmd, add--no-override; with dotenv, removeoverride: true. Otherwise thePORTin.envreplaces the release’s port and the new release fails its check. The deploy log warns about env-cmd without--no-override. - HOST: xCloud sets it to
127.0.0.1. Listen on that address. An app that listens only onlocalhostcan bind to the IPv6 address and fail the health check. - Health check: xCloud requests
/on the new release (for a Hybrid app, its API path). Any answer below 500 passes, so a redirect or a 404 is fine. A 500 or no answer fails it.
Step 3: Shut down gracefully
When the old release stops, let it finish what it is doing. Close the server when the process gets a stop signal:
for (const signal of ['SIGTERM', 'SIGINT']) {
process.on(signal, () => server.close(() => process.exit(0)));
}
nginx already sends new requests to the new release before the old one stops, so this only affects requests and jobs that are still running.
Step 4: Deploy and check the releases
Deploy as usual. The card lists each release with its commit. The newest one that passed its check is Live.

A Node.js rollback starts the kept release on the idle port, checks it and then switches, so it can take up to a minute. See How to roll back a deployment.
Your own ecosystem file
A Node.js site can keep its own PM2 ecosystem file in Release mode. If the repository has an ecosystem.config.js or ecosystem.config.cjs file in its root, each release starts from it instead of the start command.
- What is kept: each app’s env, Node arguments, memory restart and cluster mode and instances settings. To set up cluster mode, see Run a Node.js app on all CPU cores with PM2 cluster mode.
- What changes: xCloud sets
PORTandHOSTfor the web app in each release, and turns watch off. The deploy log says so: “Release mode uses ecosystem.config.js; watch is disabled for this slot.” - Before turning it on: deploy once with Release mode off, so the app runs from the file. Otherwise turning on is refused with “The ecosystem app is not running from this site. Deploy the site normally, then turn release mode on.” For a file with workers the message is “Deploy the site normally so its web app is running, then turn release mode on.”

A web app with background workers
The file can hold one web app plus background workers, for example a queue worker and a cron worker:
module.exports = {
apps: [
{ name: 'web', script: 'server.js' },
{ name: 'queue', script: 'worker.js' },
{ name: 'cron', script: 'cron.js' }
]
};
- The web app is the PM2 process that serves the site. xCloud finds it when you turn Release mode on and saves its name. Keep that name in the file. Every app in the file needs its own name.
- Each deploy switches the web app with no downtime, as described above. Then xCloud restarts the workers from the new release and checks them for about five seconds. The deploy log says: “Restarting background workers after the web switch; workers, including any with a fixed port, have a short restart gap.”
- Workers have a short restart gap. Only the web app runs a second copy during a deploy, so it never goes down. Each worker stops and starts again from the new release, so make your workers safe to stop and restart.
- A worker you remove from the file is stopped on the next deploy.
- Turning Release mode off stops the workers it manages and starts your own ecosystem file again. If your ecosystem file fails its check (for example a fixed PORT or a broken file), xCloud starts the site from its start command instead and leaves the file unchanged.
After a successful deploy the newest release is Deployed and Live:

When a worker fails
If a worker crashes or keeps restarting in its first seconds, the deploy fails. The new web release stays live, because it already passed its health check. The deployment output names the worker and prints its last log lines:
Error: Worker "queue" failed to stay running. The web stays on the new release. Its last log lines:
The card shows that release as Failed and Live at the same time:

Read the log lines in the deployment output on the Deployments page, fix the worker and deploy again. To go back to the previous web release, click Rollback on its row.
A saved reload line in the deploy script
If your deploy script has a line that only reloads the root ecosystem file, such as pm2 startOrReload ecosystem.config.js --update-env, you can keep it. During a release deploy, xCloud skips that line and starts the release itself. The deploy output shows, for example: “Line 4 skipped: release mode starts this release from ecosystem.config.js itself.” The line runs again in normal deploys after you turn Release mode off.

Other pm2 commands in the deploy script are still refused, with their line number.
Settings that are refused
The deploy fails before going live, and the output names the file, the line and the reason. If your file is ecosystem.config.cjs, the message names that file. For example:
- “the saved web app “…” is missing. The file has: …. Restore the web app name, then retry.”
- “Worker “…” belongs to another app. Give this worker a different name, then retry.” Another PM2 process on the server already uses that name.
- “PORT is fixed. Read process.env.PORT instead of a constant, then retry.”
- “args contains a port flag. Remove it and make the app read process.env.PORT, then retry.” For
node_argsthe message starts with “node_args contains a port flag”. - “cron_restart can restart or move a release slot independently. Remove it, then retry.” The same applies to
cronandincrement_var. - If you add workers to a site that turned Release mode on with one app: “The current release does not identify one web app safely. To add workers, turn release mode off and on, then retry.”
- A reload line that names another file: “Deploy script line … must reload the root ecosystem.config.js file selected by release mode. Use the same ecosystem file, then retry.”
The PORT, port flag and cron rules apply only to the web app, not to workers.
The full list is in Release mode messages and fixes.
Turning Release mode off
Turning off checks the site first and refuses before it moves any files. It stops the workers Release mode manages and starts your own ecosystem file again. If the root ecosystem file fails its check, for example because it sets a fixed PORT or is broken, xCloud starts the site from its start command and does not touch the file. The log says: “Turning off starts the site from its start command; the root ecosystem file is left unchanged.” If the deploy script reloads the root ecosystem file and the saved web app is no longer in it, turning off is refused: “Turning off needs the saved web app in the root ecosystem file, because deploy script line … reloads it. Restore the saved web app (or remove that line from the deploy script), then turn release mode off again.” If a turn-off stops partway, turn it off again to finish.
A repository that commits .env is refused
Release mode keeps .env in a shared folder. If your repository tracks a .env file, every deploy is refused and the card shows a red Failed row while the previous release stays Live:

The reason is in the deployment log on the Deployments page: “The commit tracks .env; release mode keeps it in … Remove it from the repository, then deploy again.” Remove .env from the repository, add it to .gitignore, and manage the values in xCloud instead (Environment variables and Git deployments).
Serving mode and other limits
- Serving mode: you can’t change it while Release mode is on. Turn release mode off, change the serving mode, then turn it on again.
- PM2: a deploy script line that changes PM2 processes (for example
pm2 restart) is refused with its line number. A line that only reloads your root ecosystem file is skipped instead. - Ecosystem file: one web app plus any number of workers in the root file. The web app can’t have a fixed port or a cron restart. Two web apps in one file are not supported. See Your own ecosystem file.
Frequently asked questions
Which port does my app listen on in Release mode?
xCloud sets the PORT environment variable for each release, alternating between two ports, and sets HOST to 127.0.0.1. Read the port from process.env.PORT instead of hard-coding it.
Why was my deploy refused with ‘The commit tracks .env’?
Release mode keeps .env in a shared folder and links it into every release, so the repository must not contain a .env file. Remove .env from the repository (and add it to .gitignore), then deploy again.
Can I keep my own PM2 ecosystem file in Release mode?
Yes. A root ecosystem.config.js or ecosystem.config.cjs runs in each release, with its env, Node arguments, memory restart and cluster settings. It can hold one web app plus background workers such as a queue or cron worker. Watch is turned off during Release mode. A deploy script line that only reloads that file is skipped during a release deploy; other pm2 commands in the deploy script are still refused with their line number.
What happens to my PM2 workers when a deploy fails?
The web app switches first, with no downtime. Then xCloud restarts the workers from the new release and checks them for about five seconds. If a worker does not stay running, the deploy fails with the worker’s name and its last log lines, and the new web release stays live. The card shows that release as Failed and Live. Fix the worker and deploy again.
Can I change the serving mode while Release mode is on?
No. Turn release mode off, change the serving mode, then turn it on again.
Related guides
- How to use zero-downtime deployments (Release mode)
- How to deploy a Node.js application
- Release mode messages and fixes
- How to update Node.js
If you run into any issues with zero-downtime deployments for your Node.js app, feel free to reach out to our support team.