Container stuck in "Starting" phase and repeating npm start loop
omercikan
FREEOP

4 months ago

Hello,

I’m facing a persistent issue with my Node.js backend deployment.
The build process completes successfully, but when the container starts, it gets stuck in an infinite loop showing repeated logs like this:

Starting container
npm warn config production Use `--omit=dev` instead.
> backend@1.0.0 start
> node dist/server.js

It keeps repeating endlessly, and the service never becomes “Live”.
No specific error message is displayed — it only loops the same “Starting container” and “npm warn config production” lines.

I’ve already tried:

  • Setting NPM_CONFIG_PRODUCTION=false

  • Adjusting start and build commands

  • Ensuring environment variables (like PORT, DB_URI, NODE_ENV, etc.) are properly set

  • Disabling the worker service (the issue also occurs on the main backend)

But the problem persists — it seems the container restarts continuously or fails to pass the healthcheck without showing why.

Could you please check if this is related to the Railway build environment or container startup process?

Thank you in advance.

Solved$10 Bounty

Pinned Solution

omercikan
FREEOP

4 months ago

Hey everyone, I finally figured out what was causing the issue.
It turned out that the problem wasn’t with Railway itself, but with MongoDB Atlas. The container couldn’t connect to my database because Atlas was blocking Railway’s IP.

I went to Network Access in my MongoDB Atlas project and added Railway’s IP address (you can also use 0.0.0.0/0 just to test).
After that, the deployment worked perfectly and my /health endpoint started responding again.

Hope this helps anyone running into the same 502 error!

8 Replies

Railway
BOT

4 months ago

Hey there! We've found the following might help you get unblocked faster:

If you find the answer from one of these, please let us know by solving the thread!


4 months ago

Failing a healthcheck will never be accompanied by a why.

What does that route look like?


samgordon

Failing a healthcheck will never be accompanied by a why.What does that route look like?

omercikan
FREEOP

4 months ago

My healthcheck route looks like this:

app.use("/health", (req, res) => {
  res.status(200).send("OK");
});

The route works fine — it always returns a 200 response.
The server is active and running, but whenever I send any request (even a simple one), the Railway domain keeps returning 502 Bad Gateway.

Do you know what could cause this issue even though the healthcheck succeeds and the container stays active?


omercikan

My healthcheck route looks like this:app.use("/health", (req, res) => { res.status(200).send("OK"); });The route works fine — it always returns a 200 response.The server is active and running, but whenever I send any request (even a simple one), the Railway domain keeps returning 502 Bad Gateway.Do you know what could cause this issue even though the healthcheck succeeds and the container stays active?

4 months ago

Do you have a PORT variable set to the port you’re using?


samgordon

Do you have a PORT variable set to the port you’re using?

omercikan
FREEOP

4 months ago

No, there isn’t a PORT variable set in Railway right now.


omercikan

No, there isn’t a PORT variable set in Railway right now.

4 months ago

Can you please set one that matches the port you're using


samgordon

Can you please set one that matches the port you're using

omercikan
FREEOP

4 months ago

I tried it but it didn't work


omercikan
FREEOP

4 months ago

Hey everyone, I finally figured out what was causing the issue.
It turned out that the problem wasn’t with Railway itself, but with MongoDB Atlas. The container couldn’t connect to my database because Atlas was blocking Railway’s IP.

I went to Network Access in my MongoDB Atlas project and added Railway’s IP address (you can also use 0.0.0.0/0 just to test).
After that, the deployment worked perfectly and my /health endpoint started responding again.

Hope this helps anyone running into the same 502 error!


Status changed to Solved samgordon 4 months ago


Loading...