To deploy an Astro site on Modelence, add a modelence.config.json file whose build runs npm run build and whose static entry serves the dist folder, then run npx modelence@latest deploy. For pages rendered on demand, add the Node adapter and start its server with HOST=0.0.0.0 node dist/server/entry.mjs instead. Modelence is a managed cloud on AWS that builds the site, serves it in one of 17 regions and can run managed MongoDB, Postgres and Redis databases next to it.
This guide starts from the minimal template of Astro 7 and deploys it as a static site with no server process at all, which is how most Astro sites run. It then adds @astrojs/node for pages that render on every request, reads Postgres from one of them and covers what to change before real traffic arrives. If your site already builds, skip to Deploy a static site, or to Render pages on demand if it uses an adapter. For a single-page app without Astro see Vite, and for a full-stack React or Vue app see Next.js or Nuxt.
Astro on Modelence at a glance
- How it runs
- A static site is served straight from dist with no server process; with the Node adapter, node dist/server/entry.mjs runs in a long-lived container
- Adapter
- None for static pages; @astrojs/node in standalone mode for pages rendered on demand, server islands, actions and sessions
- Routes
- A request for /about is answered from dist/about/index.html, so Astro's default build output needs no rewrite rules
- Variables
- Values read with import.meta.env are fixed when the site builds; secrets declared with astro:env are read when the server runs
- Regions
- 17 regions on AWS, with the site, its server and its databases in the one you pick
- Databases
- Managed MongoDB, Postgres and Redis next to the site, with production backups at least every six hours
- Price
- A free plan, and paid plans from $20 a month with that $20 included as usage
Before you start
- Node.js 22.23.4 or newer, which Astro 7 asks for, and npm
- A Modelence account, which you can create for free
- Optionally, Claude Code, Cursor or Codex, if you want your coding agent to write the config and run the deploy
Create an Astro site
npm create astro@latest sets up a project from one of Astro's templates. --template minimal picks the smallest one, --install runs npm install, and --yes accepts the defaults for the remaining questions. In package.json, dev runs astro dev, build runs astro build and preview runs astro preview, and engines asks for Node.js 22.23.4 or newer.
Every file in src/pages becomes a page. Add an about page next to the template's home page:
---
// src/pages/about.astro
// The frontmatter runs when the page is rendered: during astro build for a
// static page, or on every request for a page rendered on demand.
const title = 'About us'
---
<html lang="en">
<body>
<h1>{title}</h1>
</body>
</html>
astro build writes it to dist/about/index.html, a folder with an index.html for every page, so the URL stays /about.
npm create astro@latest my-site -- --template minimal --install --no-git --yes
cd my-siteRun the site locally
Start the development server and open http://localhost:4321/about:
npm run dev
Astro reads a .env file in the project root while you work. To skip the file, connect the project to a Modelence local environment: npx modelence@latest setup signs you in and picks an app and environment, and npx modelence@latest dev runs your dev script with that environment's variables.
To look at the production build, run npm run build and then npm run preview. Astro's docs say astro preview is not designed to be run in production, and the deploy below doesn't need it.
npx modelence@latest setup
npx modelence@latest devAdd a database
- MongoDB
MONGODB_URI - Postgres
DATABASE_URL - Redis
REDIS_URL
Modelence hands the server the connection strings for its managed MongoDB, Postgres and Redis as environment variables. Production databases are backed up at least every six hours, and connections are encrypted in transit. MongoDB comes in as MONGODB_URI, and Postgres and Redis use the names you give them in modelence.config.json, usually DATABASE_URL and REDIS_URL.
A static page can read a database while the site builds, but the result is fixed until the next deploy. For data that changes, read it in a page rendered on demand. Install a Postgres client with npm install pg and npm install -D @types/pg, declare DATABASE_URL in the env schema as in the step above, and create one connection pool for the server in src/lib/db.ts:
// src/lib/db.ts
import pg from 'pg'
import { DATABASE_URL } from 'astro:env/server'
// One pool per server process, shared by every request.
export const db = new pg.Pool({ connectionString: DATABASE_URL })
Then query it from the frontmatter of a page that renders on every request:
---
// src/pages/items.astro
import { db } from '../lib/db'
// Render on every request, so the page always shows the current rows.
export const prerender = false
const { rows } = await db.query<{ id: number; name: string }>(
'SELECT id, name FROM items ORDER BY id'
)
---
<html lang="en">
<body>
<ul>
{rows.map((item) => <li>{item.name}</li>)}
</ul>
</body>
</html>
The frontmatter runs only on the server, so the query and the connection string never reach the browser. A database you already run at Supabase or Neon keeps working: declare its URL in env with "type": "secret" and enter the value when the deploy asks for it. Run migrations against the environment's database before you deploy, and keep them out of the start command, because every container runs it.
This config runs the server and creates a Postgres database and a Redis cache for it:
{
"$schema": "https://cloud.modelence.com/schema/modelence.config.json?version=1",
"resources": {
"web": {
"type": "service",
"image": "node-22-slim",
"build": { "commands": ["npm ci", "npm run build"] },
"start": { "commands": ["HOST=0.0.0.0 node dist/server/entry.mjs"] },
"healthCheck": { "type": "http", "path": "/api/health" }
},
"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" }
}
}Deploy a static site
Without an adapter, astro build renders every page to HTML in dist, and the site needs no server of its own. The web service builds on the official Node.js image with npm ci and npm run build, and the static entry serves the dist folder at /. List the build commands yourself, because a service without build runs only npm install and would never create dist. There is no start command, so no process of yours runs, and the platform answers every request from the files:
- A file that exists is sent as it is, such as
/favicon.svg. - A path that matches a folder gets that folder's
index.html, so/aboutand/about/both getdist/about/index.html. - Pages from dynamic routes work the same way, because
getStaticPathsgives each one its own folder indist.
Add the file to the root of the repository and commit it:
{
"$schema": "https://cloud.modelence.com/schema/modelence.config.json?version=1",
"resources": {
"web": {
"type": "service",
"image": "node-22-slim",
"build": { "commands": ["npm ci", "npm run build"] },
"static": [{ "path": "/", "dir": "dist" }]
}
}
}Adjust the config for your project
npm ciinstalls exactly whatpackage-lock.jsonlists. With pnpm or Yarn, usecorepack enable && pnpm install --frozen-lockfileorcorepack enable && yarn install --frozen-lockfileinstead, because the Node.js images come with Yarn 1 and no pnpm.- If
outDirinastro.config.mjspoints somewhere other thandist, setdirto the same folder. - For a site served under a sub-path, set
base: '/docs'inastro.config.mjsand the staticpathto"/docs". - Set
rooton the service when the site sits in a folder of a monorepo, such asapps/web. Thediris then relative to that folder. - Never add
astro devorastro previewas astartcommand. The static entry already serves the build. - Keep
node-22-slimunlessengines.nodeinpackage.jsonasks for a newer major version.
Set variables for the build
A static page runs its frontmatter during astro build, so every import.meta.env value it reads is written into the HTML at that moment. Variables that start with PUBLIC_ can also reach scripts in the browser, and the rest stay in the HTML that the build renders. Declare each variable the build needs in env with the build scope. Leave out value for anything that differs between environments, and the deploy asks for it, after which you can change it in the dashboard under Environment variables. A token for a headless CMS that the build reads content with is a secret that only the build needs:
// modelence.config.json
{
"$schema": "https://cloud.modelence.com/schema/modelence.config.json?version=1",
"resources": {
"web": {
"type": "service",
"image": "node-22-slim",
"build": { "commands": ["npm ci", "npm run build"] },
"static": [{ "path": "/", "dir": "dist" }]
}
},
"env": {
"PUBLIC_SITE_URL": { "scopes": ["build"] },
"CMS_TOKEN": { "type": "secret", "scopes": ["build"] }
}
}
Every deploy to an environment builds with that environment's values, so the sandbox can read draft content while production reads published content, from the same commit. A changed value takes effect on the next deploy, because a restart doesn't rebuild the pages. Never give a secret the PUBLIC_ prefix, because a browser script that reads it would put it in a file every visitor downloads.
Render pages on demand
A page that shows data that changes, such as a logged-in user or rows from a database, can render on every request instead of once at build time. That needs an adapter, and on Modelence it is Astro's Node.js adapter, which npx astro add node --yes installs and adds to astro.config.mjs in standalone mode:
// astro.config.mjs
import { defineConfig } from 'astro/config'
import node from '@astrojs/node'
export default defineConfig({
adapter: node({
mode: 'standalone',
}),
})
Pages stay static by default, and a page or endpoint opts out with export const prerender = false. Add a health route the platform can call to decide when a new container is ready, in src/pages/api/health.ts:
// src/pages/api/health.ts
import type { APIRoute } from 'astro'
// Render on every request, so the route answers from the running server.
export const prerender = false
export const GET: APIRoute = () => Response.json({ status: 'ok' })
astro build now writes the server to dist/server/entry.mjs and the static pages and browser files to dist/client. The server reads PORT, which Modelence sets, and listens only on localhost unless HOST is set, so the start command sets HOST=0.0.0.0. It also serves the prerendered pages and the files in dist/client, so the service needs no static entry. Replace the config with:
{
"$schema": "https://cloud.modelence.com/schema/modelence.config.json?version=1",
"resources": {
"web": {
"type": "service",
"image": "node-22-slim",
"build": { "commands": ["npm ci", "npm run build"] },
"start": { "commands": ["HOST=0.0.0.0 node dist/server/entry.mjs"] },
"healthCheck": { "type": "http", "path": "/api/health" }
}
}
}Read secrets when the server runs
In server code, import.meta.env is also read when the site builds. In our test, an on-demand endpoint that returned import.meta.env.MY_SECRET kept sending the value from the build after the server started with a different one, while process.env.MY_SECRET returned the new value. For secrets such as a database URL or an API key, declare them in the env.schema of astro.config.mjs and import them from astro:env/server, which reads them when the server runs:
// astro.config.mjs
import { defineConfig, envField } from 'astro/config'
import node from '@astrojs/node'
export default defineConfig({
adapter: node({ mode: 'standalone' }),
env: {
schema: {
DATABASE_URL: envField.string({ context: 'server', access: 'secret' }),
},
},
})
The build doesn't need the value, and a page that reads a variable the server didn't get answers with an error that names it, while the rest of the site keeps working. On Modelence, declare API keys with "type": "secret" and no value in modelence.config.json. The deploy asks you for each one, and afterwards members of the environment can view or change it in the dashboard, where every view is logged.
Check the build locally
npx modelence@latest verify rehearses the deploy on your machine without signing in. It copies the files a deploy would upload, runs the build commands from modelence.config.json and starts the result through the same entrypoint the cloud container uses, on a random PORT. It then checks that / answers and lists which declared variables the build and the server got. Both configs in this guide end with GET / -> 200 and modelence.config.json verified. A build that fails here fails in the cloud too.
npx modelence@latest verifyDeploy
In the project directory, run:
npx modelence@latest deploy
The command opens the browser so you can sign in, choose or create the organization, app and environment, and fill in variables the environment doesn't have yet. It then uploads the project and streams the build until the new version is live. The first deploy to an environment asks for an AWS region, and everything in that environment is created there. Later deploys can skip the prompts with --app <app> --env <env>.
The site is served at <app>-<environment>.cloud.modelence.app, and you can add your own domain in the dashboard under Domains. Each app comes with a sandbox and a production environment, and both deploy from the same file, each with its own build.
Let your coding agent do it
In Claude Code, Cursor or Codex, paste Deploy using https://modelence.com/skill.md in the project. The agent reads the docs, writes modelence.config.json for the site, runs the build and the deploy, and asks you whenever a step needs your account.
Production readiness
Keep serving for 10 seconds after SIGTERM
When a deploy replaces a container, Modelence sends it SIGTERM, and requests can still reach it for about 10 seconds after that. The Node adapter's standalone server has no SIGTERM handler of its own and exits at once. In our test, 3, 8 and 13-second requests that were running at that moment were all cut off, and every request sent after it was refused. To keep answering, start the server through a small wrapper. Add start.mjs at the project root and set the start command to HOST=0.0.0.0 node start.mjs:
// start.mjs
// Starts the server from `astro build` and keeps it serving for 10 seconds
// after SIGTERM, while the load balancer may still send it requests.
// The adapter's own server exits at once on SIGTERM, so start it ourselves.
process.env.ASTRO_NODE_AUTOSTART = 'disabled'
const { startServer } = await import('./dist/server/entry.mjs')
const { server } = startServer()
process.once('SIGTERM', () => {
setTimeout(() => {
// Stop accepting connections, let open requests finish, then exit.
server.server.close(() => process.exit(0))
server.server.closeIdleConnections()
}, 10_000)
})
With the wrapper, requests sent up to 9.4 seconds after SIGTERM still got a 200, one sent at 10.6 seconds was refused, and the 3, 8 and 13-second requests that were already running all finished. A static site has no server of its own, so it needs none of this.
Let hashed files cache for a year
Astro gives the scripts, styles and images it bundles a content hash in their name, so a file's URL changes whenever its content does. For a static site, Modelence caches hashed files in an assets folder as immutable for a year and revalidates everything else on each load. Astro names that folder _astro by default, so rename it in astro.config.mjs:
// astro.config.mjs
import { defineConfig } from 'astro/config'
export default defineConfig({
build: {
// Hashed scripts, styles and images go to dist/assets instead of dist/_astro.
assets: 'assets',
},
})
The pages keep revalidating, so a deploy shows at once. With the Node adapter, its server already sends the year-long header for files in _astro.
Keep state out of the container
Containers have no persistent disk, and every deploy replaces all of them, so files written to disk are gone after the next deploy. The Node adapter stores Astro sessions in files on the container's disk unless you set a session driver, so point session.driver in astro.config.mjs at Redis from the same region, as Astro's sessions guide describes. Store uploads in object storage and everything else in the database. Under Configure in the dashboard, run the service on two or more containers so the site stays up when one is replaced or an availability zone goes down. Availability explains how deploys and rollbacks keep it serving.
Run background jobs as their own service
Keep queue consumers and scheduled jobs out of the Astro server. With more than one container, each one would pick up the same job, and a reminder email would go out once per container. Add a second service to modelence.config.json with its own start command, "healthCheck": { "type": "none" } and "rollout": "recreate", as Multiple services describes.
Watch logs and metrics
The Node adapter prints a line when the server starts and logs errors from pages and endpoints, but not each request, so log what you need with console.log or a logger. The environment's Logs page shows the build and everything the server writes, with nothing to set up. For traces and metrics, add a telemetry resource and point the standard OpenTelemetry variables at it, as the modelence.config.json reference describes.
Modelence vs Vercel, Netlify and Cloudflare for Astro sites
Astro sites are most often deployed on Vercel, Netlify and Cloudflare, which serve the static build from their own networks and run pages rendered on demand as functions or Workers. Cloudflare acquired the company behind Astro in January 2026, and the framework stays open source and runs on any host. The table is based on each platform's own docs and pricing pages in December 2026.
| Platform | Static pages | Pages rendered on demand | Pricing |
|---|---|---|---|
| Modelence | Served from dist by the site's containers in one of 17 regions, with no adapter | @astrojs/node as a long-running Node.js server, next to managed MongoDB, Postgres and Redis | Free plan; paid plans from $20 a month with $20 of usage included |
| Vercel | Deployed with no configuration and served from Vercel's CDN | @astrojs/vercel builds the routes as Vercel Functions, in iad1 by default, with ISR as an option | Hobby is free with usage limits; Pro is $20 a month with one seat and $20 of credit, plus $20 for each added seat |
| Netlify | Detects Astro, builds with astro build and serves dist from its CDN | @astrojs/netlify runs them as Netlify Functions, in Ohio by default, with middleware on Edge Functions | Free with 300 credits a month; Personal $9 and Pro $20 a month |
| Cloudflare | Workers static assets, with no Worker code | @astrojs/cloudflare runs them on Workers, with D1, KV and Hyperdrive as bindings | Static asset requests are free; Workers Free has 100,000 requests a day, and Paid starts at $5 a month |
For a content site with no backend of its own, all three serve the files from locations close to visitors around the world, and Cloudflare doesn't charge for static asset requests. Vercel and Netlify optimize images through their adapters and give every pull request a preview URL, and Cloudflare suits pages that should render close to visitors and keep their data in D1. Modelence fits when the site renders pages from a database you also run, because one file describes the site, its server and its databases, the server runs as an ordinary long-lived Node.js process, and everything stays in the region you pick. Modelence vs Vercel and Vercel alternatives compare the platforms in more depth.
Next steps
- modelence.config.json referenceStatic entries, start commands and health checks
- Environment variablesBuild scopes for import.meta.env, and secrets for the server
- DatabasesManaged MongoDB, Postgres and Redis for pages rendered on demand
- Multiple servicesRun an API or a worker next to the Astro site
- AvailabilityHow deploys, health checks and rollbacks keep the site up
Frequently asked questions
How do I deploy an Astro website?
Run astro build, which writes the site to dist, and serve that folder as static files. On Modelence, a modelence.config.json with the build commands npm ci and npm run build and a static entry for dist does both, and npx modelence@latest deploy builds and serves it. A site that uses the Node adapter starts its server with HOST=0.0.0.0 node dist/server/entry.mjs instead.
Do I need an adapter to deploy Astro?
Not for a static site, because astro build writes plain HTML, CSS and JavaScript that any host can serve. You need one for pages rendered on demand, server islands, actions and sessions. On Modelence that is @astrojs/node in standalone mode, which runs as an ordinary Node.js server.
What is the difference between static and on-demand rendering in Astro?
A static page is rendered once during astro build and served as a file, so it is fast and cheap but shows the data from build time. A page with export const prerender = false is rendered by the adapter's server on every request, so it can read a database, cookies or the logged-in user. Most sites keep pages static by default and render on demand only where a page needs fresh data.
Why are my environment variables not working in Astro?
Values read with import.meta.env are fixed when astro build runs, in server code as well as in the browser, so a value that is set only when the server starts never reaches them. For a static site, make the variable available to the build and deploy again after changing it. For pages rendered on demand, declare secrets in the env schema in astro.config.mjs and import them from astro:env/server, or read process.env, both of which take the value when the server runs.
Why can't I reach my Astro Node.js server?
The standalone server from @astrojs/node listens only on localhost unless the HOST variable is set, so a container or load balancer can't reach it. Start it with HOST=0.0.0.0 node dist/server/entry.mjs. It takes the port from PORT, which Modelence sets for you.
Can I use astro preview in production?
No, Astro's docs say astro preview is for checking the build locally and is not designed to be run in production. Serve dist as static files, or with the Node adapter run node dist/server/entry.mjs, which is what the configs in this guide do.
Can I deploy Astro with Docker?
Yes. A static site is only the dist folder, and a site with the Node adapter needs dist and its production dependencies, because the server imports packages such as astro itself from node_modules when it runs. On Modelence you don't need a Dockerfile: the official Node.js image with npm ci, npm run build and the start command does the same, and a service can also build from a Dockerfile you already have.
Can I deploy Astro to Cloudflare Pages?
Cloudflare's own Astro guide now deploys to Workers instead, with static assets for a static site and @astrojs/cloudflare for pages rendered on demand. Cloudflare acquired the company behind Astro in January 2026 and said the framework stays open source and keeps working on other hosts, so the same site can deploy to Modelence with the Node adapter.
Can I deploy Astro to Vercel?
Yes, Vercel deploys a static Astro site with no configuration, and pages rendered on demand need @astrojs/vercel, which builds them as Vercel Functions. On Modelence the same site keeps @astrojs/node and runs as one long-lived server next to its database.
How much does it cost to host an Astro site on Modelence?
It can cost nothing on the free plan, which runs one instance that sleeps when idle. Paid plans start at $20 a month, all of which counts toward usage, and each container is billed by the hour by size, from about $9 a month for the smallest one with 0.25 vCPU and 0.5 GB of memory, which is enough to serve a static site.