Node/Express backend keeps crashing / restart loop on Railway
alis0047
PROOP

14 days ago

My backend service on Railway repeatedly crashes/restarts (crash loop). When it’s briefly up, some API calls work, then the service dies again. This is impacting auth flows and other API routes.

Stack

  • Node.js 20+ / Express

  • PostgreSQL (Railway)

  • Prisma

  • Deployed on Railway (Docker)

  • Frontend is separate (Cloudflare Pages)

Service Backend API service (Node/Express). (If the form forces “Service”: select this backend service or select “N/A” if it’s not tied to a specific Railway template.)

Symptoms

  • Service restarts repeatedly

  • Health endpoints may pass briefly, then fail after restart

  • Auth routes fail intermittently / after restart

What I suspect A required environment variable is missing or misconfigured (JWT secret and/or other required config). This is a known critical issue in our deployment notes. :contentReference[oaicite:1]{index=1}

What I’ve tried

  • Verified deployment is pointing to the correct repo/service

  • Rebuilt/redeployed the service

  • Checked that DATABASE_URL points to the Railway Postgres instance

  • Reviewing env var parity vs local .env.example

What I need help with

  1. Best way to identify exactly what is triggering the crash loop on Railway (recommended log view / crash reason extraction).

  2. Confirmation if Railway is killing the container due to:

    • missing env vars at runtime (e.g., JWT secret),

    • failing health check,

    • out-of-memory,

    • Prisma migrate/generate step failing on boot.

Info that may help you debug

  • Backend runs Prisma on startup

  • Expected required env vars include (not limited to):

    • NODE_ENV

    • PORT

    • DATABASE_URL

    • JWT_SECRET (critical)

    • plus 3rd party keys if routes initialize them

  • Health routes exist: /health, /health/live, /health/ready, /health/detailed

Requested next steps from Railway

  • If possible, please point me to the first fatal error in logs right before the restart, and whether the restart is app-exit (crash) vs platform health/OOM termination.

  • If there’s a standard Railway checklist for crash loops (health checks / start command / Dockerfile / env var validation), please share.

$20 Bounty

4 Replies

Railway
BOT

14 days ago

This thread has been marked as public for community involvement, as it does not contain any sensitive or personal information. Any further activity in this thread will be visible to everyone.

Status changed to Open Railway 14 days ago


xmrafonso
FREETop 5% Contributor

14 days ago

Hey there,

Any chances you are not binding to a railway port correctly? That would make the healthchecks to fail in that case.

Would be nice if you could provide an exit code too


alis0047
PROOP

14 days ago

Thanks! Log Explorer shows the backend server repeatedly starting with the log line “Server running on port 3001” (service reliable-strength).

I’m listening on 0.0.0.0 and using process.env.PORT with fallback 3001, so the app is binding (currently port 3001). Exit codes I’m seeing in logs are 0 (worker process exit), not a non-zero crash exit code.


rohit123890
HOBBY

14 days ago

Temporarily disable Prisma + auth init.

If container stays alive → it’s Prisma or auth init crashing.


alis0047
PROOP

12 days ago

But the logs don't even why its crashing


Status changed to Open brody 12 days ago


Loading...