To deploy Astro to Railway, add the @astrojs/node adapter in standalone mode, push the repository, and create a Railway service from it with the start command node ./dist/server/entry.mjs. Set HOST=0.0.0.0; Railway provides PORT and the Astro server reads it. Railway runs long-lived services, so it suits SSR sites and sites that sit next to a database on the same platform.
Key Takeaways
- Railway runs a process, not a folder of files, so Astro needs a server:
@astrojs/nodestandalone or a static file server.- Bind to
0.0.0.0; the server reads Railway’sPORTvariable automatically.- Set the Node.js version in
package.jsonengines; current Astro needs 22.23.4 or newer.- For a purely static site, a static host is simpler and usually cheaper.
1. Add the Node adapter
# Terminal
npx astro add node
// astro.config.mjs
import { defineConfig } from 'astro/config';
import node from '@astrojs/node';
export default defineConfig({
site: 'https://www.example.com',
adapter: node({ mode: 'standalone' }),
});
Pages stay prerendered by default; only routes with export const prerender = false render on demand. Our rendering modes guide explains the choice.
2. Add a start script and Node.js version
{
"scripts": {
"dev": "astro dev",
"build": "astro build",
"start": "node ./dist/server/entry.mjs"
},
"engines": {
"node": ">=22.23.4"
}
}
Railway’s builder detects a Node.js project, runs npm run build and then npm start. The engines field tells it which Node.js major to install; check the build log to confirm the version it picked.
3. Create the service
- In Railway, create a new project and choose Deploy from GitHub repo.
- Under the service’s Variables, add
HOSTwith the value0.0.0.0. - Add any secrets your server routes need, such as API keys.
- Under Settings and then Networking, generate a Railway domain or add your own.
Every push to the connected branch triggers a new deploy. If the deploy log shows the server starting but the domain returns an error, the usual cause is the server listening on localhost instead of 0.0.0.0.
Environment variables
Railway injects variables at both build and run time. Values read in prerendered pages are baked in at build; values read in on-demand routes are read when the request runs. Define them with astro:env so Astro validates them and keeps secrets server-side:
// 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' }),
},
},
});
Railway can reference a database service’s variables directly, for example DATABASE_URL=${{Postgres.DATABASE_URL}}. See our environment variables guide.
Static sites on Railway
If the site has no on-demand routes, you can skip the adapter and serve dist/ from a container. The Nginx Dockerfile in our Docker tip works on Railway: add it to the repository root and Railway builds from it. Change Nginx to listen on the port Railway assigns, or set the service’s target port to the one Nginx uses.
That said, a static Astro site has nothing to run, so static hosts such as Cloudflare Pages or Netlify are a better fit. Our free hosting comparison and the static deploy docs cover them. Themes from our Astro theme catalog are static by default, so they only need Railway if you add server routes.
FAQ
Can I deploy a static Astro site to Railway?
Yes, by serving dist/ from a container such as Nginx. Railway runs services rather than hosting files, so a static host is usually simpler for sites without server routes.
Why does my Astro app on Railway show “Application failed to respond”?
The server is probably listening on localhost. Set HOST=0.0.0.0 in the service variables. The standalone server reads Railway’s PORT automatically.
What start command does Astro use on Railway?
node ./dist/server/entry.mjs, which runs the standalone server built by @astrojs/node. Put it in an npm start script so Railway finds it.
Which Node.js version does Railway use for Astro?
Railway picks a version from the engines field in package.json or its default. Set "node": ">=22.23.4" for current Astro releases and confirm in the build log.