Deploy a Vibe-Coded App on Railway
AI coding tools like Cursor, Claude Code, Bolt, and Lovable generate working applications quickly. Deploying that code to production often surfaces issues that did not appear in local development. This guide covers how to deploy AI-generated code on Railway and fix the most common problems.
For Lovable-specific deployment, see the dedicated Lovable guide.
How Railway detects your app
When you deploy code to Railway, Railpack analyzes your repository to detect the language and framework. It then installs dependencies, runs the build, and starts the application.
For most AI-generated projects, auto-detection works without extra configuration. If it fails, you can add a Dockerfile for full control over the build.
Deploy from GitHub
- Push your AI-generated code to a GitHub repository.
- Create a new project on Railway.
- Click + New > GitHub Repo and select your repository.
- Railway auto-detects the framework and starts the first build.
- Generate a public domain under Settings > Networking.
If the build fails, check the build logs for errors and see the troubleshooting section below.
Deploy from the CLI
If your code is not on GitHub, deploy directly from your local machine:
The CLI uploads your code, builds it on Railway, and deploys the result.
Common issues with AI-generated code
Hardcoded ports
AI tools often hardcode the port number (e.g., app.listen(3000)). Railway injects the port via the PORT environment variable. Your app must read it:
Also ensure the app binds to 0.0.0.0, not localhost or 127.0.0.1. Binding to localhost makes the app unreachable from outside the container.
Missing environment variables
AI-generated code may reference environment variables that exist in a local .env file but are not set on Railway. Check your code for references to process.env.* or os.environ and add each variable in the Railway Variables tab.
Do not commit .env files to your repository. Add sensitive values directly in the Railway dashboard.
Missing start command
If Railway cannot detect how to start your app, add a start command in the service settings. Common examples:
| Framework | Start command |
|---|---|
| Next.js | npm start |
| Express | node server.js |
| FastAPI | uvicorn main:app --host 0.0.0.0 --port $PORT |
| Flask | gunicorn app:app --bind 0.0.0.0:$PORT |
No build step configured
Some AI-generated projects have build steps that are not captured in package.json scripts. Verify that npm run build (or the equivalent for your framework) produces the expected output. If your project needs a custom build command, set it under Settings > Build > Build Command.
Database connection issues
If your app expects a database, AI tools sometimes generate connection strings that point to localhost. On Railway, databases run as separate services. Add a database to your project and reference its connection URL as an environment variable.
Health check failures
Railway checks that your service responds on its assigned port. If your app takes a long time to start or does not respond to HTTP requests, the deploy may fail. Check that:
- The app binds to
0.0.0.0and thePORTvariable. - The app responds to requests within the health check timeout.
- There are no startup errors in the deployment logs.
Adding a Dockerfile
If auto-detection does not work for your project, add a Dockerfile to the repository root. Here is a generic Node.js example:
Railway automatically uses the Dockerfile when present.
Next steps
- Railpack: How Railway auto-detects and builds your app.
- Environment Variables: Configure secrets and connection strings.
- Deployments: Build settings, start commands, and deploy triggers.
- Deploy a Lovable App: Lovable-specific deployment guide.
- Troubleshooting Builds: Fix common build failures.