Medusa Backend Builds Successfully but Server Not Running After Deploy

Anonymous
FREE

a month ago

Hi Railway Support,

I’ve deployed a customized Medusa.js v2 turborepo to Railway. I am not trying to use template for deploying.

The build completes successfully, but after deployment, the server doesn't seem to start - there’s no response from the expected public URL.

info: Server is ready on port: 9000

This is ideal log that I should get if the project was running correctly.

My Questions:

  • Is there something I need to configure additionally to expose the port to the public URL?

  • Is the medusa develop command compatible with Railway deployments, or should I use a different command for production?

  • How can I debug if the process is alive but not accepting external requests?

$10 Bounty

2 Replies

anthonysette
HOBBY

a month ago

Tough to give you a definitive direction without more information but here is what I can say

Railway automatically assigns a PORT environment variable that your application needs to use. The issue is likely that your Medusa server is hardcoded to port 9000, but Railway expects it to bind to the dynamically assigned port.

Solution: Ensure your Medusa configuration uses the Railway-provided PORT:

// In your server startup
const port = process.env.PORT || 9000;

If you are using Medusa v2, check your medusa config as well

module.exports = {
  projectConfig: {
    http: {
      port: process.env.PORT || 9000,
      host: "0.0.0.0" // Important: bind to all interfaces
    }
  }
}

To answer your questions more directly

1. Port configuration for Railway: Yes - you need to configure your Medusa server to use process.env.PORT instead of hardcoded port 9000, and bind to host 0.0.0.0.

2. medusa develop vs production command: No - medusa develop is not compatible with Railway deployments. Use medusa start for production instead.

3. Debugging live but unresponsive process:

  • Check Railway deployment logs for errors after "Server is ready"

  • Verify the server is binding to Railway's assigned PORT (not 9000)

  • Confirm host is set to 0.0.0.0 not localhost

  • Add a /health endpoint to test basic connectivity

The most likely issue is your server binding to port 9000 on localhost instead of Railway's dynamic port on all interfaces.


lofimit
HOBBY

a month ago

The answer by @anthonysette is most likely AI, so it's hard to read, I'll give my own answer.

It could be a port binding issue. Railway sets its own PORT env var and your app has to listen to that, not hardcoded 9000. Also make sure it's binding to 0.0.0.0, not localhost, or it won’t be accessible from the outside.

Make sure to not use medusa develop on Railway as that’s for local dev. Use medusa start or whatever your prod start script is.

This is how to do it in medusa-config.js: serverPort: process.env.PORT || 9000 so it isn't hardcoded and uses Railway's PORT env var.