How to deploy a Node.js API to production in 2026
Express, Fastify, Hono, or plain HTTP — every Node.js API follows the same deploy shape. Step-by-step tutorial for shipping your Node API to a real URL with environment variables, custom domain, and free SSL.
Dmytro Chervonyi
Co-founder & CMO, livemy.app
Last updated
TABLE OF CONTENTS
item

AI Summary
Node.js APIs follow a consistent deploy pattern regardless of framework — Express, Fastify, Hono, Koa, plain HTTP module. The host runs your Node process, exposes a port, sets environment variables for database connections and API keys, routes traffic. This tutorial walks the end-to-end deploy for any Node.js API, the production server practices (PM2 alternatives, process management on managed hosts), the database connection patterns that work without leaks, and the five gotchas that quietly break Node APIs in production. Plus the 3-minute flow to livemy.app at $20/month flat with custom domain and free SSL.
What you need before starting
A working Node.js API that responds locally (
npm startornode server.js)package.jsonwith all dependencies and astartscriptThe Node.js version your code uses (specified in
package.jsonenginesfield)Your
.envfile with database URLs, API keys, secretsGitHub account or a ZIP of your project
Total deploy time: roughly 10–20 minutes for a typical Express/Fastify API.
Step-by-step: deploy on livemy.app
Step 1: Production-ready your package.json
The host runs your code with whatever's in the start script. Make sure it works.
Two important points. First, start uses node, not nodemon (nodemon is dev only). Second, engines pins the Node version so the host doesn't pick a wildly different default.
Step 2: Listen on the right port
Hosts inject a PORT environment variable telling your app which port to listen on. Hardcoded ports break deploys.
The 0.0.0.0 host is critical — listening on localhost means external traffic can't reach you.
Step 3: Push to GitHub
Confirm .env is gitignored. Confirm node_modules is gitignored.
Step 4: Sign up at livemy.app, pick Maker
Go to livemy.app, click Start free, pick Maker ($20/month). Always-on is required for APIs serving real traffic.
Step 5: Connect the GitHub repo
In the dashboard: New project → Connect repo. livemy.app reads package.json, detects Node.js, sets the build to npm install and the start to npm start.
Step 6: Set environment variables
Open your local .env, paste each variable into Project Settings → Environment Variables on livemy.app. Common Node API variables:
DATABASE_URL— PostgreSQL/MySQL/MongoDB connection stringJWT_SECRET— token signing key (32+ random characters)NODE_ENV=production— enables performance optimizations and disables verbose loggingAPI keys for any third-party services your code calls
Step 7: Deploy
Click Deploy. livemy.app runs npm install, then npm start. Typical deploy time: 1 to 3 minutes for a small-to-medium Node API.
Once live, test:
Should return whatever your health endpoint serves.
Step 8: Custom domain
Click Add custom domain, paste your API domain (e.g., api.yourapp.com), update DNS at your registrar. SSL fires automatically. Done.
Five things that quietly break Node APIs in production
1. Hardcoded localhost / port 3000
Symptom. Deploy looks successful in logs but the live URL returns connection refused.
Cause. Code says app.listen(3000, 'localhost') or just app.listen(3000). The host runs your app on a different port and external traffic can't reach localhost.
Fix. Use process.env.PORT and bind to 0.0.0.0 as shown in Step 2.
2. Database connection pool exhausted
Symptom. First few requests work; after 5–10 minutes, every request hangs or errors with "too many connections".
Cause. Opening a new database connection on every request without releasing it. The Postgres server's max connection limit gets hit; new connections wait or fail.
Fix. Use a connection pool. For pg: const pool = new Pool({ connectionString: process.env.DATABASE_URL, max: 10 }). For Prisma, the default connection pooling works fine. Never call new Client().connect() in a request handler without explicit cleanup.
3. Missing NODE_ENV=production
Symptom. App runs but slowly. Memory usage higher than expected. Verbose logs in production.
Cause. Without NODE_ENV=production, Express keeps view caching off, dev mode messages on, and other dev-friendly defaults that hurt perf.
Fix. Always set NODE_ENV=production in environment variables for production deploys. livemy.app does this by default but worth confirming.
4. Unhandled promise rejections crash the process
Symptom. The API works for hours, then suddenly dies. Logs end with "UnhandledPromiseRejection".
Cause. An async function threw and nothing caught it. As of Node 15+, unhandled rejections crash the process by default.
Fix. Wrap every async route handler in a try/catch, or use an error middleware like express-async-errors for Express. Add a process-level catch as a safety net:
5. CORS not configured for browser clients
Symptom. Browser frontend can't call the API. Console shows "blocked by CORS policy".
Cause. Default Node behavior denies cross-origin requests. Browser clients hit preflight failures.
Fix. Install the cors middleware: app.use(cors({ origin: 'https://yourfrontend.com' })). For multiple origins or dynamic checks, pass an array or a function. Don't use origin: '*' in production with credentials — it's a security risk.
Cost comparison for one Node.js API
Heroku Eco: $5/month + sleeps after 30 min. $14/month with Postgres add-on.
Render Starter + Pro workspace: $7 + $25 = $32/month for always-on.
Railway Hobby: $5/month base + usage = $5–20/month.
Fly.io: ~$1.94–5/month for a small always-on Machine.
livemy.app Maker: $20/month flat with custom domain, SSL, monitoring.
Self-hosted on a $5 VPS: $5/month plus systemd, nginx, automated SSL setup.
FAQ
Do I need PM2 on a managed host?
No. Managed hosts (livemy.app, Render, Railway, Heroku) handle process management for you. If the Node process crashes, the host restarts it. PM2 is for self-hosted VPS deployments where you're managing process lifecycle yourself.
Can I deploy a TypeScript API?
Yes. Two approaches. Easiest: add a build script in package.json (tsc compiles TS to JS in dist/), update start to node dist/server.js. livemy.app runs the build before the start. Alternative: use tsx or ts-node to run TS directly in production — simpler but a bit slower at startup.
How do I add a database?
Three options. Free managed Postgres from Supabase or Neon — paste the connection string into DATABASE_URL. Free MongoDB from Atlas. Or have livemy.app provision a Postgres alongside your project. For Node APIs specifically, Supabase is the most ergonomic if you want auth and storage included.
What's the cheapest way to host a Node.js API?
For very low traffic or hobby use: Fly.io at ~$2/month for a small always-on Machine. For predictable production: livemy.app Maker at $20/month flat with everything included. For multiple APIs on one VPS: self-host with Dokploy on a $10 VPS.
How do I scale to multiple replicas?
On livemy.app Pro tier, scale vertically (more CPU/RAM per container). For horizontal scaling (multiple replicas behind a load balancer), Render, Railway, and Fly.io all support multi-replica deployments. Add a Redis cache for session sharing if your API uses sessions.
Should I use Express, Fastify, or Hono?
Personal preference, deploys identically. Express is the default, biggest ecosystem. Fastify is faster (~2–3x) and has a cleaner plugin system. Hono is the smallest and works on edge runtimes (Cloudflare Workers). All three deploy to livemy.app, Render, Railway, or Fly.io without changes.
Deploy your Node API — 3 minutes, flat $20/month
If your Node API is on GitHub and the start script works locally, you're three minutes away from a live URL.
→ Start free on livemy.app · Auto-detect for any Node.js project with a package.json. Custom domain, SSL, monitoring on Maker at $20/month flat.
Hit one of the five gotchas? Email hello@livemy.app with the error log. Replies inside one business day.
Read next

Dmytro Chervonyi
,
Co-founder & CMO, livemy.app
Co-founder & CMO at livemy.app. 12 years as a CMO scaling SaaS from $0 to $10M+ ARR across marketing, sales, and infra products and tools. Now building the missing step between AI-built code and a live URL — for non-developers who’d rather ship than learn DevOps.


