Problem with node
zxq041
HOBBYOP

5 months ago

Hello, since yesterday I have a problem with my projects on railway because it reads them as caddy (only static files) and it doesn't want to read the node backend, please help me.

$15 Bounty

4 Replies

dardameiz
PRO

5 months ago

Hey! Railway's auto-detection switched your Node backend to Caddy, which means it's not finding your Node files properly. Make sure you have a package.json in your repo root - Railway uses that to detect Node projects. If it's there but still detecting as Caddy, you can force Node by adding a nixpacks.toml file with [phases.setup] providers = ["node"] or set a custom start command in your Railway service settings. Did something change in your repo structure yesterday? Check if your package.json got moved or deleted.


alexxdf28-hue
FREE

5 months ago

Option 1: Adjust Root Directory (Recommended)

If your package.json is in a subfolder (e.g., /backend), tell Railway where it is:

  1. In your Railway service dashboard, go to Settings.
  2. Find the Root Directory option.
  3. Enter the name of your folder (e.g., backend).
  4. Redeploy.

Option 2: Force Node.js Start Command

If the file structure is correct, manually force the Node.js build process:

  1. Go to the Settings tab of your service.
  2. In the Deploy section, find the Start Command.
  3. Set it to your Node.js start script (e.g., npm start).

Make sure to

  • Ensure your package.json is in the directory you specified.
  • Make sure the package.json includes a valid "start" script (e.g., "start": "node index.js").

This worked for me so i hope it helps!


anarchistmanifesto
TRIAL

5 months ago

Hey @zxq041

yeah this is annoying when it happens. Railway probably cant see your package.json so it defaults to caddy because it thinks youre just serving static files

Quick fix is what @dardameiz said but heres the step by step

If your package.json is in a subfolder:

  • go to your service settings in railway
  • scroll to root directory
  • type in whatever folder has your package.json like backend or server
  • redeploy

If package.json is at the root but still broken:

You can manually override the detection by adding a nixpacks.toml file at your repo root

[phases.setup]
providers = ["node"]

or just set a custom start command in railway settings like npm start or node index.js depending on what your package.json has

@alexxdf28-hue has the right idea too with checking your start script in package.json. make sure thats actually there

Did you push any changes yesterday that couldve moved files around or deleted package.json by accident? thats usually what causes this

let us know if youre still stuck and drop your logs if nothing works


dardameiz
PRO

5 months ago

Hey, could you solve it? 🙂


Welcome!

Sign in to your Railway account to join the conversation.

Loading...