To deploy a Node.js app with Modelence, make the server listen on the PORT variable, describe its build and start commands in modelence.config.json and deploy it with one command from the project directory. Modelence is a managed cloud that runs on AWS: it builds the app on an official Node.js image, runs it as containers in the region you pick out of 17 and creates the MongoDB, Postgres and Redis databases it needs in the same region.
This guide does that for a small Express API, from a new project to a production URL. The steps are the same for Fastify, Hono, NestJS or any other Node.js server, and if you already have an app, skip to Run the app locally.
Node.js on Modelence at a glance
- Start command
- `node server.js` after `npm ci`, on the official `node-22-slim` image or any Node.js 18+ image you name
- Port and health check
- Listens on `PORT` (3000) on all interfaces, and an HTTP check needs a 2xx from `/health` within 4 seconds
- Deploys
- New containers take traffic only after they pass health checks, and a version that keeps crashing rolls back
- Shutdown
- `SIGTERM` first, then up to 30 seconds before `SIGKILL`, adjustable from 2 to 120 with `stopTimeout`
- Regions
- 17 AWS regions, with the app, its databases and their backups in the one you pick
- Databases and backups
- Managed MongoDB, Postgres and Redis in the app's region over TLS, with production data snapshotted at least every 6 hours
- Price
- Free plan to start, and paid plans from $20 a month with the $20 included as usage
Before you start
- Node.js 20 or newer and npm
- A Modelence account, which you can create for free
- Optionally, Claude Code, Cursor or Codex, if you'd rather have your coding agent write the config and run the deploy
Create an Express app
Create a project and install Express:
mkdir my-api && cd my-api
npm init -y
npm install express
Then add server.js with one route. The server reads its port from the PORT variable and falls back to 3000 on your machine. Modelence sets PORT in production, and a server that listens on a hardcoded port never receives traffic.
const express = require('express');
const app = express();
app.use(express.json());
app.get('/', (req, res) => {
res.json({ message: 'Hello from Node.js' });
});
const port = Number(process.env.PORT) || 3000;
app.listen(port, () => {
console.log(`Listening on port ${port}`);
});Run the app locally
Add a start script for production and a dev script that restarts the server when a file changes:
"scripts": {
"dev": "node --watch server.js",
"start": "node server.js"
}
Start the development server with npm run dev and open http://localhost:3000.
You can also connect the project to a Modelence local environment, so the app runs on your machine with the environment's database connection strings and variables and they never need to be copied into a .env file. npx modelence@latest setup opens the browser, where you sign in and pick or create an app and environment. After that, start the app with npx modelence@latest dev instead of npm run dev. It runs your dev script with the environment's variables, and the environment's Overview in the dashboard shows the app while it runs.
npx modelence@latest setup
npx modelence@latest devAdd a database
- MongoDB
MONGODB_URI - Postgres
DATABASE_URL - Redis
REDIS_URL
Your Node.js server connects to managed MongoDB, Postgres or Redis on Modelence the way it would to any database, through a connection string in an environment variable. The databases run in the app's region, connections use TLS and production data is backed up at least every six hours.
Read process.env.MONGODB_URI for MongoDB, and for Postgres and Redis whatever name you give them in modelence.config.json, typically DATABASE_URL and REDIS_URL. Pass it to the client your app already uses, such as the MongoDB driver, pg, Prisma, Drizzle or a Redis client. Create the client once when the server starts rather than on every request, so requests share its connections.
If the database stays where it is, such as Supabase or Neon, the connection code doesn't change, and its URL goes in env with "type": "secret".
Migrations, whether from Prisma, Knex or your own scripts, should run against the environment's database before the deploy. Putting them in the start command means every container runs them, several at once during a rollout. Steps that are safe to repeat, like prisma generate, are fine in the build command.
Declaring a Postgres database or Redis cache takes a few lines in modelence.config.json, and the deploy creates it before the new API version starts:
{
"resources": {
// "api": the app's service, as in the next step
"main-db": { "type": "postgres", "plan": "postgres-1gb" },
"cache": { "type": "redis" }
},
"env": {
"DATABASE_URL": { "type": "resource", "resource": "main-db", "output": "url" },
"REDIS_URL": { "type": "resource", "resource": "cache", "output": "url" }
}
}Describe the app in modelence.config.json
Modelence builds a Node.js app as a Node.js service. It runs your build commands on an official Node.js image, then starts the process with your start commands, here npm ci and node server.js. Add modelence.config.json at the root of the repository and commit it with the app:
{
"$schema": "https://cloud.modelence.com/schema/modelence.config.json?version=1",
"resources": {
"api": {
"type": "service",
"image": "node-22-slim",
"build": { "commands": ["npm ci"] },
"start": { "commands": ["node server.js"] }
},
"main-db": { "type": "postgres", "plan": "postgres-1gb" }
},
"env": {
"DATABASE_URL": { "type": "resource", "resource": "main-db", "output": "url" },
"STRIPE_SECRET_KEY": { "type": "secret" }
}
}Adjust the config for your project
npm ciinstalls frompackage-lock.json. With pnpm, usecorepack enable && pnpm install --frozen-lockfile, with Yarn 1,corepack enable && yarn install --frozen-lockfile, and with Yarn 2 or newer,corepack enable && yarn install --immutable.- For a TypeScript app, compile it in the build and start the output, for example
"build": { "commands": ["npm ci", "npm run build"] }and"start": { "commands": ["node dist/server.js"] }. Don't start the app withnodemon,ts-node-devortsx watch, which are development tools. - The server has to listen on
PORTand on all interfaces, whichapp.listen(port)does by default. Don't pass127.0.0.1orlocalhostas the host. - Pick
imageto matchengines.nodeinpackage.jsonif it sets one.node-22-slimis the default, and any Node.js version from 18 up works. If the app needs system packages such asffmpegor Chromium, build it from a Dockerfile instead, as described in Dockerfile services. - Declare keys and tokens with
"type": "secret"and no value. The deploy asks you for them in the browser, and you can change them later in the dashboard under Environment variables, where every view of a secret is logged. - If the same project has a frontend built with Vite, build it in
buildand serve it with"static": [{ "path": "/", "dir": "client/dist" }]. The platform serves the files, and requests that match no file reach the server.VITE_variables need"scopes": ["build", "runtime"]. - If the app lives in a subdirectory of a monorepo, set
rooton the service.
Check the build locally
Before the first deploy, run the same commands Modelence will run, in the same order, and check that the app answers on http://localhost:3000. A deploy runs the same build, so anything that fails here fails there too.
npm ci && PORT=3000 node server.jsDeploy
Run the deploy command in the project directory:
npx modelence@latest deploy
It opens the browser, where you sign in, pick the organization, app and environment (or create them) and enter any required variables the environment doesn't have yet, such as STRIPE_SECRET_KEY above. Then it uploads the project and follows the build until the app is live. You pick the AWS region the first time you deploy an environment, and its containers and databases are created there. Next time, pass --app <app> --env <env> to preselect the target.
The first deploy creates the databases in resources, starts the app once they're ready and attaches the environment's URL, <app>-<environment>.cloud.modelence.app, to the api service. To use your own domain, add it in the dashboard under Domains. Every app has a sandbox and a production environment, and the same file deploys to both.
Let your coding agent do it
Paste Deploy using https://modelence.com/skill.md into Claude Code, Cursor or Codex in your project. The agent reads the docs, writes modelence.config.json for your project, checks the build and runs the deploy, and it stops to ask you whenever a step needs your account.
Production readiness
Add a health check
By default Modelence counts a container as healthy once it accepts connections on its port. An HTTP check is stricter: the container has to answer a path with a 2xx status within 4 seconds, so a new version that starts but can't serve requests never takes traffic. Add a route:
app.get('/health', (req, res) => {
res.json({ status: 'ok' });
});
Then point the service's check at it in modelence.config.json:
"healthCheck": { "type": "http", "path": "/health" }
Redirects are followed, so register the route before any middleware that redirects or rejects signed-out requests.
Shut down cleanly
When a container stops, for example during a deploy, the process gets SIGTERM, and requests can still reach it for about 10 seconds after that. To finish them without dropping any, keep serving for 10 to 15 seconds, then close the server and exit:
const server = app.listen(port);
process.on('SIGTERM', () => {
setTimeout(() => {
server.close(() => process.exit(0));
}, 10_000);
});
The container gets 30 seconds between SIGTERM and SIGKILL by default, which leaves time for this. Change it with stopTimeout on the service.
Keep state out of the process
Anything a Node.js process keeps in memory or on local disk lives in one container and is gone on the next deploy. Common cases are the default MemoryStore of express-session, files saved by multer with dest, and in-memory rate limit counters. Move sessions and counters to Redis, and send uploads to object storage, so any container can serve any request.
Then raise the service to two or more containers under Configure, which keeps the API up through a crash or a zone outage. Availability explains how rollouts and rollbacks work.
Run background jobs as their own service
Don't run a queue consumer or a scheduled job, such as a setInterval loop, inside the API process. With several containers, each one would run every job, and emails or charges would go out twice. Add a second service to modelence.config.json with its own start command:
"worker": {
"type": "service",
"build": { "commands": ["npm ci"] },
"start": { "commands": ["node worker.js"] },
"healthCheck": { "type": "none" },
"rollout": "recreate"
}
The worker listens on no port, so it has no health check, and "rollout": "recreate" stops the old worker before the new one starts. Keep it on one container if its jobs must not run twice, or have each job take a lock in the database. Multiple services has the details.
Watch logs and metrics
Logs need no setup. Everything the app writes to its output, including console.log, shows on the environment's Logs page. For traces and metrics, add a telemetry resource, tie the standard OpenTelemetry variables to it and start the server with node --require @opentelemetry/auto-instrumentations-node/register server.js, so requests and database calls are traced without code changes. Deploy setup has the full example.
Modelence vs Railway, Render and Fly.io for Node.js
Railway, Render and Fly.io are the platforms people compare most often for a Node.js backend, and all four run your server as a regular Node.js process listening on a port. The figures below come from each platform's own docs and pricing pages in November 2026.
| Platform | How a Node.js app runs | Databases | Regions | Pricing model | Best for |
|---|---|---|---|---|---|
| Modelence | Build and start commands in modelence.config.json on an official Node.js image, or your own Dockerfile | Managed MongoDB, Postgres and Redis, backed up at least every 6 hours | 17 (AWS) | Free plan, then from $20 a month with $20 of usage included | Production APIs that should run on AWS in a chosen region next to managed databases |
| Railway | Railpack detects Node.js and runs npm start, or Railway builds your Dockerfile | Postgres, MySQL, Redis and MongoDB templates, with backups you turn on | 4 | Hobby $5 or Pro $20 a month including that much usage, then compute billed by the second | Getting an app and a database running with very little setup |
| Render | A Node web service with the build and start commands you set | Managed Postgres from $6 a month, Redis-compatible Key Value from $10 a month | 5 | Workspace plan ($0, $25 or $499 a month) plus a fixed price per instance, from $7 a month | APIs with steady traffic and a predictable bill per service |
| Fly.io | fly deploy builds a Docker image and runs it on Fly Machines | Managed Postgres from $4 a month | 17 | Pay as you go, about $2.19 a month for a shared CPU Machine with 256 MB | Apps that should run in several regions close to their users |
Railway is the quickest way from a repository to a running app, and its per-second billing suits an API whose load comes and goes. Render's fixed instance prices are easier to budget for steady traffic, and its free web services work well for demos, although they spin down after 15 minutes without traffic. Fly.io covers 17 regions on six continents and is the better fit when the same app should run near users in many of them at once. Modelence fits when the API has to run on AWS in a region you choose, with MongoDB, Postgres and Redis managed and backed up next to it and failed deploys rolled back for you. For more detail, see Railway vs Render, Railway alternatives and Modelence vs Vercel.
Next steps
Frequently asked questions
How do I deploy a Node.js app to production?
To deploy a Node.js app to production, make the server read its port from the PORT variable, start it with node rather than a development tool, and run it on a platform that keeps the process up and supplies the database. On Modelence you put the build and start commands in modelence.config.json and deploy from the project directory, and Modelence builds the app on an official Node.js image and runs it as containers in the AWS region you pick.
Can I host a Node.js app on AWS without setting up AWS myself?
Yes, Modelence runs your Node.js app on AWS and manages the containers, databases and backups, so you don't set up any AWS services yourself. You describe the app in modelence.config.json and pick one of 17 regions on the first deploy, and the app's containers and databases are created in that region.
Can I host an Express server on Vercel?
Yes, Vercel deploys an Express app with zero configuration and runs the whole app as a single Vercel Function on Fluid compute, which scales with traffic. On Vercel, express.static() doesn't serve files, so static assets go in the public directory, and the Vercel Functions limits apply to the app. If you want the server to run as one long-running Node.js process, for example to hold WebSocket connections or to run a worker next to the API, a platform that runs containers, such as Modelence, Railway or Render, fits it better.
Do I need PM2 to run Node.js in production?
You don't need PM2 for a Node.js app on Modelence, because the platform already keeps the process running: it starts your start command, replaces a container that crashes or fails its health checks, and runs as many containers as you set. Start the server with node directly, such as node server.js, and scale by raising the container count under the service's Configure page instead of using PM2 cluster mode. PM2 is still useful on a server you manage yourself.
Can I host a Node.js app with WebSockets or Socket.IO?
Yes, a Node.js app on Modelence runs as a long-running server, so WebSocket and Socket.IO connections stay open with no maximum duration. A container's connections close when it stops during a deploy, so clients need to reconnect, which Socket.IO does by default. With more than one container, use the Socket.IO Redis adapter with a managed Redis cache so events reach clients on every container, and set transports to ['websocket'] on the client, because HTTP long-polling needs sticky sessions.
Can I deploy a Node.js app written in TypeScript?
Yes, Modelence runs a TypeScript Node.js app once it is compiled: add npm run build to the build commands and start the compiled output with node, such as node dist/server.js. Watch tools like tsx watch or nodemon are for development and don't belong in the start command.
Which Node.js versions are supported?
Modelence runs Node.js 18 and newer, and node-22-slim is the default image. Set image in modelence.config.json to a major version such as node-24-slim or an exact one such as node-22.23.1-alpine, ideally matching engines.node in package.json.
How do I run background jobs or cron jobs in a Node.js app?
On Modelence, run background and scheduled jobs in a separate worker service in modelence.config.json with its own start command, such as node worker.js, instead of inside the web server. If the web server ran them, every web container would run each job and it would happen more than once. Keep the worker on one container if its jobs must not run twice, or have each job take a lock in the database.
Can I use my own domain?
Yes, you can serve a Node.js app on Modelence from your own domain: add it in the dashboard under Domains and attach it to the service that serves the app. Paid plans include unlimited custom domains, and every environment also gets its own URL on cloud.modelence.app.
How much does it cost to host a Node.js app on Modelence?
You can host a Node.js app on Modelence for free on the free plan, which runs one instance that sleeps when idle. Paid plans start at $20 a month with the same $20 included as cloud usage, so you pay only for usage above that, and they are needed for managed Postgres and Redis. The plan price covers the whole team, with no charge per seat.