How to Deploy a Node.js Application with xCloud
Updated November 27, 2026 · 5 min read
You can deploy a Node.js application to xCloud directly from a public or private Git repository. xCloud analyzes the repository, selects Node.js as the application type when it detects a supported Node.js project, and prepares the deployment settings for you to review.
This guide shows how to deploy an Express-style Node.js application with Deploy via Git, including the branch, runtime, serving mode, port, environment variables, build script, and post-deployment settings.
Prerequisites
Before you begin, make sure you have:
- An active xCloud account.
- A connected server with enough resources for your application.
- A Git repository containing your Node.js application.
- Access to the repository if it is private.
- A start script in
package.json, such asnpm run start, for an SSR or API application.
Step 1: Start a Deploy via Git deployment
Open the target server in xCloud, select Add New Site, and choose Deploy via Git. The deployment screen lets you search for a public repository or switch to a private repository provider.

Step 2: Choose the repository and confirm the app type
Paste the repository URL or select a repository from your connected Git provider. xCloud analyzes the repository and preselects an application type.
Confirm that Node.js is selected. If the detected type is incorrect, choose Node.js manually before continuing.

Repository detection is a starting point, not a replacement for review. Check the branch, runtime, commands, port, and environment values before deployment.
Step 3: Choose a branch and domain
Select the branch that xCloud should deploy. For the first deployment, you can use the generated Staging domain (no DNS). To deploy on your own hostname instead, select Use a live domain instead and complete the domain configuration shown in xCloud.

The staging domain is useful when you want to verify the application before changing DNS for a production domain.
Step 4: Configure how the application is served
In Build & serving, select the mode that matches the application:
| Serving mode | Use it for |
|---|---|
| SSR (Node process) | Express, NestJS, Next.js SSR, APIs, and other applications that keep a Node.js process running |
| Static | Applications that produce static files and do not need a persistent Node.js process, such as a Docusaurus documentation site |
| Hybrid | Applications that need both generated static assets and a running Node.js process |
For an SSR or API application, enter the command used to start the process and the port on which the application listens. The example below uses npm run start and port 3000.

Your application must listen on the same port configured in xCloud. When the application supports it, read the port from the PORT environment variable instead of hard-coding it.
xCloud runs the application as one PM2 process. To use every CPU core of the server, run the app in PM2 cluster mode with your own ecosystem file.
Step 5: Review the Node.js runtime
Expand Advance and confirm the Node.js Version. Choose a version supported by your application and its dependencies. See How to change the Node.js version for the versions you can pick.
Under the version, xCloud shows the package manager it found in your repository, for example Package manager: pnpm 11 (found in the repository). xCloud installs your dependencies with that package manager, so you don’t need to switch your project to npm. The line appears only for pnpm, Yarn and Bun; a repository that uses npm shows no line.

xCloud picks the package manager in this order:
- The
packageManagerfield inpackage.json, such as"packageManager": "[email protected]". When the field names a full version like this, xCloud installs exactly that version on the server. - The lockfile at the root of the repository:
pnpm-lock.yaml(pnpm),yarn.lock(Yarn),bun.lockorbun.lockb(Bun),package-lock.jsonornpm-shrinkwrap.json(npm). - npm, when the repository has neither.
A Bun lockfile does not move your app to a container. When your app uses a Node.js framework, such as Next.js, Nuxt, Vite, Astro or Express, it deploys here as a Node.js app and Bun installs its packages. Only an app that runs on Bun itself, for example one whose start script runs bun or that uses Elysia, deploys in the Bun container. An Express or other server app with no start script may still go to the Bun container, because xCloud cannot tell how to start it. Add a start script that runs node (for example node server.js) to package.json to deploy it as a Node.js app. Push the change and start the deployment again. Under Advance, the form now shows Node.js Version and the note Package manager: bun (found in the repository). See Deploy Python, Ruby, Go, Java and Bun Apps from Git.
If the repository has lockfiles from two different package managers, for example package-lock.json and yarn.lock, xCloud uses npm and shows the warning Two lockfiles found; npm is used. on the form. Delete the lockfile you don’t use, or add a packageManager field to package.json, then start the deployment again.
The Site User is the Linux user that owns the site files. Keep the generated value unless you have a specific naming requirement.

Step 6: Add environment variables
Use the Environment file (.env) field for non-secret and secret runtime configuration required by your application. You can also specify the repository path to the environment file when it is not located at the project root.

For example:
NODE_ENV=production
PORT=3000
Do not commit production credentials to Git. Enter them in xCloud’s environment editor and rotate any credential that was previously exposed in repository history.
Need a PostgreSQL database? On an Nginx server with managed PostgreSQL Ready, set Database engine to PostgreSQL when you create the site. xCloud creates the database and role and adds DATABASE_URL and the DB_* connection settings to the site’s environment for you. See How to Install Managed PostgreSQL and pgAdmin in xCloud.
Step 7: Review the build and deploy script
The Build & deploy script runs after xCloud pulls the selected branch. xCloud fills it with the install command for your package manager and, when your package.json has a build script, the build command for the same package manager. Review the commands and adjust them to match your build process.

xCloud uses these install commands:
| Package manager | Install command |
|---|---|
| npm | npm install --no-audit --no-fund (shown as $XCLOUD_NPM install --no-audit --no-fund in the script) |
| pnpm | pnpm install --frozen-lockfile |
| Yarn 1 | yarn install --frozen-lockfile |
| Yarn 2 and later | yarn install --immutable |
| Bun | bun install --frozen-lockfile |
xCloud treats Yarn as Yarn 2 or later when the packageManager field names version 2 or higher. If the field names no Yarn version, xCloud uses Yarn 2 or later when the repository has a .yarnrc.yml file. A frozen or immutable install stops when the lockfile doesn’t match package.json. If the deployment log shows this, run the install locally, commit the updated lockfile and deploy again.
Your own commands always win. If you change the install line in the script, xCloud runs your command as written. When the Build & deploy script switch is off, xCloud runs the install command from the table above, plus the build command if it found one in your repository.

For a repository that uses npm, the script installs dependencies and builds the project like this:
$XCLOUD_NPM install --no-audit --no-fund
npm run build
Only keep the build command when the repository defines a build script. Applications that run directly from source may not need one.
Step 8: Review the summary and deploy
Check the summary before starting the deployment. Confirm the repository, application type, domain, and serving mode. Then select Deploy.

Wait for the deployment process to finish before opening the site. If the deployment fails, inspect the deployment log for the command that failed and compare it with a successful local production build.
Manage environment variables after deployment
Open the site and select Environment to review or update its runtime variables. Updating the environment of a Node.js application restarts the managed process so the new values can take effect.

Use one KEY=value pair per line. Avoid adding comments or formatting that your application’s environment loader does not support.
Each Git deployment resets the code folder, but xCloud keeps an untracked .env in the site’s root folder. Keep .env in your .gitignore anyway: a committed .env is replaced on every deploy, and an untracked .env in a subfolder is removed. See Environment Variables (.env) and Git Deployments for how a Git deployment treats your .env file and how to keep it.
Update SSR configuration
For an application that runs as a Node.js process, open SSR Configuration to update the application port or start command. The port must be available on the server and must match the port used by the application.

Updating SSR configuration restarts the managed process and may cause brief downtime.
Verify the deployment
After the deployment completes:
- Open the configured staging or live domain.
- Confirm the expected page or API response loads.
- Check the deployment log for build errors or missing packages.
- Confirm the application is listening on the configured port.
- Exercise one application-specific flow, such as loading a server-rendered route or calling a health endpoint.
Find the application logs
Your Node.js application’s own output (startup messages, crashes and stack traces) is in the site’s PM2 Log. xCloud runs the application with PM2, so this is the first place to look when the site does not load.
- Open the site and go to Monitoring → Logs in the site menu.
- In the log picker, select PM2 Log. For a Node.js site it is usually selected already.
- Read the newest lines for the error the application printed when it started or stopped.

On an Nginx server, the same picker also has Nginx Access Log and Nginx Error Log. The Nginx error log shows whether the web server could reach your application at all. For more on the Logs page, see View Logs and Events of Your Server and Site.
Fix a 502 Bad Gateway after deployment
A 502 means the deployment finished but the web server could not reach your application. xCloud sends visitors to your application at 127.0.0.1 on the Application Port. When nothing answers there, visitors get a 502.
A common cause is an application that listens only on localhost. On current Node.js versions, localhost can resolve to the IPv6 address ::1, so the application runs and works when you test it over SSH, but nothing answers at 127.0.0.1.
Step 1: Read the PM2 Log
Open Monitoring → Logs and select PM2 Log, as shown above. If the log shows a crash on startup, such as a missing environment variable or a module that was not installed, fix that error first. Changing the address your app listens on will not help.
Step 2: Listen on 127.0.0.1 and the configured port
Change the server code so it listens on 127.0.0.1 and reads the port from PORT:
const port = process.env.PORT || 3000;
app.listen(port, '127.0.0.1', () => {
console.log(`Listening on 127.0.0.1:${port}`);
});
If your framework takes the address from an environment variable such as HOST, set it to 127.0.0.1 in the site’s Environment page instead. Use 0.0.0.0 only if something else on the server must reach the app; it also makes the app reachable by server IP and port, not only through your domain. Confirm that the port matches Application Port in SSR Configuration.
Step 3: Redeploy and check the site again
Push the change to the deployed branch. If the push does not start a deployment on its own, select Deploy Now at the top of the site page so the application restarts with the new code. Deploy Now is available on paid plans; on the Free plan, turn on Enable push to deploy in the site’s Git settings and push a new commit to the deployed branch to start a deployment. Then open the domain again. The page or API response should load, and the PM2 Log should show the application listening on the configured port.
If the site still returns 502, read the PM2 Log again: a process that keeps restarting prints the reason there. For deployments that fail or do not start, see Troubleshooting Git Deployments.
Troubleshooting
| Symptom | What to check |
|---|---|
| Build command fails | Check the Package manager line under Node.js Version and the install command in the deployment log. Commit a lockfile that matches package.json, keep only one package manager’s lockfile, and confirm the Node.js version and the scripts in package.json. |
| Warning: Two lockfiles found; npm is used. | The repository has lockfiles from two package managers. Delete the one you don’t use, or set the packageManager field in package.json, then deploy again. |
| Application deploys but returns an error | Check the process start command, the PM2 Log under Monitoring → Logs, required environment variables, and external service credentials. |
| Site returns 502 Bad Gateway | Make sure the application listens on 127.0.0.1 (not only localhost) on the configured port, then redeploy. See Fix a 502 Bad Gateway after deployment. |
| Static assets return 404 | Confirm the build output directory and whether the application should use Static or Hybrid serving mode. |
| New environment values are not applied | Save the Environment page and allow the managed process to restart. |
Turn on Release mode for zero-downtime deployments
A normal deploy restarts your app, so visitors can get 502 errors for a moment. Turn on Release mode in ‘Site’ → ‘Git’ to start each release on a second port and switch traffic only after it passes a health check. See How to use zero-downtime deployments (Release mode) and Zero-downtime deployments for Node.js apps.
Frequently Asked Questions
Which Node.js version should I choose?
Choose a version supported by the application and its dependencies. If the repository declares an engine in package.json, use a compatible version in xCloud.
Do I need a build command?
Only when the application compiles or generates production files. TypeScript, frontend bundles, and many frameworks require a build step; a small JavaScript API may not.
What port should I use?
Use the port on which the application listens, such as 3000. Keep the value consistent between xCloud’s Application Port, the PORT environment variable, and the application’s server code.
Which package manager does xCloud use for my Node.js app?
The one your repository uses. xCloud reads the packageManager field in package.json first, then the lockfile (pnpm-lock.yaml, yarn.lock, bun.lock or bun.lockb, package-lock.json or npm-shrinkwrap.json). With neither, it uses npm. If the repository has lockfiles from two different package managers, xCloud uses npm and shows a warning.
Can I deploy a private repository?
Yes. Select Private Repository, connect the supported Git provider, and choose a repository that the connected account can access.
Why does my Node.js app return 502 when it works over SSH?
The application most likely listens only on localhost, which can resolve to the IPv6 address ::1. xCloud reaches the application at 127.0.0.1 on the Application Port. Make the application listen on 127.0.0.1 on that port, then redeploy.
Where are my Node.js application logs?
Open the site, go to Monitoring → Logs, and select PM2 Log. It shows what your application prints, including startup errors and crashes.
Next steps
Once the staging deployment works, connect the production domain, configure DNS and SSL, add production environment values, and verify the application again on its final URL.
Building a Shopify app? See how to deploy a Shopify app on your own server with xCloud, which adds PostgreSQL, the Shopify keys and the app URLs to these steps.
If a deployment gets stuck, the build or start fails, or auto-deploy stops triggering, see Troubleshooting Git Deployments. The .env file path pointing at a folder instead of a file is a common cause of a failed start.
Still stuck? Contact our support team for any of your queries.