# How to Deploy a Node.js Application to Production in 2026

> Deploy a Node.js app with Kuberns. Review the runtime, build and start commands, add env vars and PostgreSQL, then verify health checks, HTTPS, and logs.
- **Author**: parth-kanpariya
- **Published**: 2025-11-10
- **Modified**: 2026-10-12
- **Category**: Deployment Guides
- **URL**: https://kuberns.com/blogs/how-to-deploy-nodejs-app/

---

To deploy a Node.js app to production, prepare a reproducible build and start command, push the tested project to GitHub, connect the repository to Kuberns, review the detected runtime and process settings, add environment variables and supporting services, and deploy. Kuberns is an Agentic AI platform for deployment, so a temporary agent can inspect the repository and propose the configuration before the managed build begins.

A production deployment is more than making the homepage respond. The application needs a supported Node.js release, a lock file, the correct port and host binding, secure secrets, health checks, graceful shutdown behavior, and a safe database migration plan. These details matter whether you are deploying a small Express API or a full-stack React, Node.js, and PostgreSQL application.

This guide covers the complete path from a local Node.js project to a verified production service, including the checks that help prevent failed starts, unreachable ports, broken database connections, and unsafe releases.

## TL;DR

- Use a Node.js version in Active LTS or Maintenance LTS status.
- Commit `package.json` and the matching npm, pnpm, or Yarn lock file.
- Define explicit build and start scripts and test them from a clean install.
- Read the platform port from `process.env.PORT` and bind the server to an accessible host.
- Keep database URLs, API keys, and session secrets outside Git.
- Connect the repository to [Kuberns](https://kuberns.com), then review the detected runtime, root directory, commands, port, and required resources.
- Deploy and verify the health endpoint, HTTPS, logs, database migrations, background work, and a real user flow.

## What Does a Node.js App Need Before Deployment?

A Node.js project that works through a local development command is not automatically production-ready. The deployment environment must be able to recreate the dependencies, build the application, start the correct process, route traffic to it, and stop it safely during a replacement or rollback.

| Requirement | What to prepare |
| --- | --- |
| Supported runtime | Pin an Active LTS or Maintenance LTS Node.js major version |
| Reproducible dependencies | Commit `package.json` and the correct lock file |
| Build process | Define a build script for TypeScript, bundling, or generated clients where needed |
| Start process | Define the exact production command rather than a development watcher |
| Port and host | Read `process.env.PORT` and bind to an accessible interface |
| Secrets | Store database URLs, API keys, and session secrets outside the repository |
| Health checks | Expose a lightweight readiness endpoint |
| Safe shutdown | Stop accepting traffic and close servers or database connections on `SIGTERM` |
| Database release | Run migrations as an explicit, controlled deployment step |
| Logs and data | Write useful logs to standard output and keep durable files outside ephemeral storage |

The official [Node.js release schedule](https://nodejs.org/en/about/previous-releases) recommends using only Active LTS or Maintenance LTS releases for production applications. Pinning the supported major version also prevents a later build from silently changing runtimes.

### Add Build and Start Scripts

The scripts depend on the application. A plain Express server may only need a start command, while a TypeScript app normally needs a build step:

```json
{
  "scripts": {
    "build": "tsc",
    "start": "node dist/server.js"
  },
  "engines": {
    "node": "24.x"
  }
}
```

Use the command that matches your package manager and committed lock file. For npm projects, `npm ci` provides a clean, reproducible installation when `package-lock.json` is present. Test the same build and start commands locally from a clean checkout.

### Read the Platform Port

Managed platforms commonly supply the listening port through an environment variable. Keep a local fallback, but do not force production traffic onto a fixed port:

```javascript
const port = Number(process.env.PORT) || 3000;

const server = app.listen(port, "0.0.0.0", () => {
  console.log(`Server listening on ${port}`);
});
```

Add a lightweight health endpoint that confirms the web process is ready. Do not make every health request perform expensive external operations.

### Handle Graceful Shutdown

When a platform replaces an instance, the application should stop accepting new traffic and finish or cancel in-flight work before exiting:

```javascript
process.on("SIGTERM", () => {
  server.close(() => {
    console.log("HTTP server closed");
    process.exit(0);
  });
});
```

Production applications may also need to close database pools, queue consumers, and other long-lived connections. Add a timeout so a stuck shutdown cannot block a deployment indefinitely.

## Best Way to Deploy a Node.js App on Kuberns

Kuberns converts the connected repository into a reviewed deployment plan. Its temporary agent can detect the framework, root directory, dependency files, ports, build commands, process commands, Dockerfiles, environment-variable names, and supporting resources. You review those proposals and provide the secrets or production decisions that cannot be inferred safely from code.

### Step 1: Prepare and Test the Repository

Confirm that the application builds and starts from a clean installation. Commit the lock file, migration files, build configuration, and scripts needed by the release. Exclude `.env`, `node_modules`, logs, local databases, and generated secrets through `.gitignore`.

Push the tested project to GitHub. If it lives in a monorepo, identify the application root so the detected configuration can be reviewed accurately.

### Step 2: Connect the GitHub Repository

Sign in to Kuberns with Google or GitHub, choose the repository deployment flow, authorize the Kuberns GitHub App, and select the organization, repository, branch, and available region.

![Connect a GitHub repository to Kuberns](https://kuberns-blogs-media.s3.ap-south-1.amazonaws.com/kuberns-registration.png)

Use only the repository access the project needs. The selected branch becomes the source for deployments, so protect it with the review and merge rules appropriate for production.

### Step 3: Review the Detected Configuration

The temporary agent analyzes the repository and proposes settings. Review the following before approving the deployment:

- Project root directory
- Node.js runtime version
- Package manager and dependency command
- Build command and output
- Production start command
- Listening port
- Environment-variable names
- Dockerfile, when the repository includes one
- Supporting database, cache, worker, or storage resources

Detection reduces repetitive setup, but it does not replace application knowledge. Confirm that a TypeScript app starts from compiled output, a monorepo points at the correct package, and the production process does not run a development watcher.

### Step 4: Add Environment Variables and Resources

Add secrets and environment-specific configuration in the dashboard rather than committing a production `.env` file.

![Add Node.js environment variables in Kuberns](https://kuberns-blogs-media.s3.ap-south-1.amazonaws.com/environment-variable-kuberns.png)

Typical variables include:

```text
NODE_ENV=production
DATABASE_URL=postgresql://...
REDIS_URL=redis://...
SESSION_SECRET=replace-with-a-secure-value
```

Attach PostgreSQL, MySQL, MongoDB, Redis, or a Node worker when the application requires it. Add persistent storage or object storage for files that must survive a redeploy. The temporary filesystem of an application process should not be treated as durable storage.

### Step 5: Deploy and Inspect the Logs

Start the deployment and watch the build output. Confirm that the expected lock file is used, compilation succeeds, the production process starts, and the server listens on the expected port.

![Node.js application deployment running on Kuberns](https://kuberns-blogs-media.s3.ap-south-1.amazonaws.com/kuberns-ai-deploying.png)

If the release fails, begin with the first meaningful error. Common causes include an unsupported runtime, a missing lock-file dependency, an incorrect monorepo root, TypeScript output that was never built, a missing environment variable, or a failed database connection.

### Step 6: Verify the Production Application

Open the public URL and health endpoint, then test an actual user flow. Verify HTTPS, database migrations, authentication, external integrations, background jobs, uploads, and WebSocket connections where the application uses them.

![Verify the deployed Node.js service in the Kuberns dashboard](https://kuberns-blogs-media.s3.ap-south-1.amazonaws.com/deployed-dashboard.png)

Do not stop at a successful build or a homepage response. Review runtime logs and metrics, generate a controlled error, and confirm that the team can identify and roll back a faulty release. If releases should follow approved branch updates, use the [GitHub auto-deploy workflow](https://kuberns.com/blogs/how-to-auto-deploy-your-apps-from-github-in-one-click/) after the first deployment is stable.

## How to Deploy React, Node.js, and PostgreSQL Together

A full-stack React, Node.js, and PostgreSQL application usually contains at least three separately configured parts: the frontend build, the Node.js API process, and the database. They may share one repository, but they should not be treated as one indistinguishable process.

For a monorepo, identify the frontend and backend root directories. Give each service its own install, build, and start command. The React frontend needs the production API base URL, while the Node.js API needs the PostgreSQL connection string and the allowed frontend origin.

| Component | Production configuration |
| --- | --- |
| React frontend | Root directory, install command, build command, output directory, API base URL |
| Node.js API | Root directory, runtime version, start command, port, CORS origin, secrets |
| PostgreSQL | Connection string, SSL requirements, connection pool, backups, migration process |
| Background worker | Separate process command, queue connection, retry and failure handling |

### Configure CORS and API URLs Explicitly

Do not hardcode `localhost` in a production frontend build. Store the public API URL in the frontend's build-time environment. On the API, allow only the intended production origins and HTTP methods rather than accepting every origin by default.

### Run PostgreSQL Migrations Safely

Treat migrations as a release operation, not something every web instance runs concurrently at startup. Prefer backward-compatible changes: add the new schema, deploy code that can work during the transition, migrate data, and remove obsolete fields only after the rollout is complete.

Use connection pooling and set sensible limits. A deployment that adds more application instances without controlling the pool size can exhaust the database even when the API itself appears healthy.

### Keep Services Close and Independently Verifiable

Choose compatible regions for the API, database, and Redis resource to avoid unnecessary latency. After deployment, test the frontend-to-API request, one database write, one read, authentication, and any queued task. Each service should expose enough logs to identify which layer failed.

## Node.js Production and Post-Deployment Checklist

- [ ] The runtime uses a supported Node.js LTS release.
- [ ] The lock file matches the selected package manager.
- [ ] Production build and start commands work from a clean checkout.
- [ ] The application reads `process.env.PORT` and binds correctly.
- [ ] `NODE_ENV` and required secrets are configured outside Git.
- [ ] A lightweight health endpoint returns the expected status.
- [ ] `SIGTERM` triggers a graceful shutdown.
- [ ] Database migrations and rollback behavior are verified.
- [ ] Connection-pool limits are appropriate for the deployed resources.
- [ ] Background workers can receive and complete a test job.
- [ ] WebSockets reconnect correctly, when used.
- [ ] Uploads and durable files are not stored only on an ephemeral filesystem.
- [ ] HTTPS, custom-domain DNS, and redirects work correctly.
- [ ] Runtime errors appear in logs without exposing secrets or personal data.
- [ ] One complete production user flow passes.

### Common Node.js Deployment Failures

| Symptom | Likely cause | What to check |
| --- | --- | --- |
| Build succeeds but the service does not start | Wrong process command or missing compiled output | Start script, build output path, application root |
| Service starts but is unreachable | Wrong port or host binding | `process.env.PORT`, host binding, health path |
| Module cannot be found | Dependency or workspace mismatch | Lock file, production dependencies, monorepo install command |
| TypeScript entry file is missing | Build step did not run or start path is wrong | Build command and `dist` output |
| Database connection fails | Missing URL, SSL setting, network, or pool configuration | Environment variable, driver settings, resource status |
| New release fails after migration | Incompatible schema change | Migration order, backward compatibility, rollback plan |

For releases that must remain available while instances are replaced, use the readiness, graceful shutdown, migration, and rollback practices in the [zero-downtime deployment guide](https://kuberns.com/blogs/zero-downtime-deployment/).

## Why Use Kuberns for Node.js Deployment?

Kuberns is designed for developers who want one reviewed workflow for the application and its supporting resources. The temporary agent proposes the deployment configuration, then the managed pipeline builds and deploys the service. After deployment, the dashboard provides access to configuration, environment variables, logs, resources, metrics, activities, domains, and service settings.

![Kuberns Agentic AI platform for Node.js deployment](https://kuberns-blogs-media.s3.ap-south-1.amazonaws.com/kuberns-home-page-new.png)

Depending on the workload, Kuberns can manage application servers, Node workers, PostgreSQL, MySQL, MongoDB, Redis, Kafka, NATS, builds, runtime processes, AWS-backed compute, networking, DNS integration, SSL, logs, metrics, alerts, and diagnostic workflows. These are documented platform capabilities, while application-level choices such as the correct start command, migration strategy, pool size, and health behavior still require developer review.

This combination is especially useful for a full-stack project because the frontend, Node.js API, database, cache, and worker can be managed as related resources without pretending they are the same process.

## Conclusion

A reliable Node.js deployment begins with the application: a supported LTS runtime, reproducible dependencies, explicit build and start commands, secure configuration, correct port binding, graceful shutdowns, safe migrations, health checks, and useful logs. Those foundations matter more than a provider comparison table.

Kuberns brings the repository analysis, deployment configuration, managed build, supporting resources, and operational dashboard into one workflow. If the application is tested and ready on GitHub, start with the [Kuberns Trial Option](https://dashboard.kuberns.com), review the proposed configuration, and verify the deployment using the production checklist above.

<a href="https://dashboard.kuberns.com" target="_blank" rel="noopener noreferrer">
  <img src="https://kuberns-blogs-media.s3.ap-south-1.amazonaws.com/CTA_banner.png" alt="Deploy a Node.js application on Kuberns" style={{ width: "100%", height: "auto" }} />
</a>

## Frequently Asked Questions About Node.js Deployment

### How do I deploy a Node.js app to production?

Use a supported Node.js LTS release, commit reproducible dependencies, define the build and start commands, push the project to GitHub, connect it to a deployment platform, add secrets and services, then deploy. Verify the health endpoint, logs, database, and HTTPS before sending production traffic to the application.

### Which Node.js version should I use in production?

Use a Node.js release in Active LTS or Maintenance LTS status and pin the supported major version for repeatable builds. Avoid Current releases for production unless the application has a tested reason to require them, and do not deploy an end-of-life release.

### Why must a Node.js app use process.env.PORT?

Managed platforms commonly provide the listening port through the `PORT` environment variable. Reading `process.env.PORT` allows the application to bind to the platform's assigned port while retaining a local fallback for development.

### Can I deploy Node.js without Docker or SSH?

Yes. A managed deployment platform can build a Node.js application directly from its repository and dependency files without SSH or a custom Dockerfile. Docker remains useful when the application needs operating-system packages or a tightly controlled runtime image.

### How do I deploy a Node.js app with PostgreSQL?

Provision PostgreSQL, store the connection string in an environment variable, configure connection pooling, run migrations as a controlled release step, and test both database connectivity and rollback behavior after deployment.

### What should I check after deploying a Node.js app?

Check the public URL, HTTPS, health endpoint, environment variables, database migrations, static assets, background jobs, WebSockets where used, uploads, logs, graceful shutdown behavior, and one complete user flow.

---
- [More Deployment Guides articles](https://kuberns.com/blogs/category/deployment-guides/1/)
- [All articles](https://kuberns.com/blogs/)