Express node web service deployment fails

Hi :slight_smile: I have configured a webservice on Render, which is built over node js, express and typescript.
I have set npm ci && npm run build as build script, then npm run start as starting script.
Logs seems ok during deployment but it stays at “in progress” status and eventualy finished in timeout. Until the timeout, my /health route can never be reached.

Below the scripts part of my package.json

  "scripts": {
    //...
    "build": "rm -rf dist && tsc --build",
    "start": "node dist/index.js",
    //...
  }

And below the code I run in order to launch the Express server:

  const PORT = process.env.PORT || 8080;
  const server = api.listen(PORT, "0.0.0.0", () => {
    console.log(`Server running on port ${PORT}`);
  });

I double checked, I have set at 10000 the PORT env var in my Render settings.

Below the code of my health route (well set in the webservice settings)

  router.get("/health", (req, res) => {
    const data = {
      uptime: process.uptime(),
      message: "Ok",
      date: new Date(),
    };

    res.status(200).send(data);
  });

Here my final logs from the deployment process:

==> Running build command 'npm ci && npm run build'...
added 197 packages, and audited 198 packages in 3s
37 packages are looking for funding
  run `npm fund` for details
found 0 vulnerabilities
> cb-api@1.0.0 build
> rm -rf dist && tsc --build
==> Uploading build...
==> Build uploaded in 7s
==> Build successful 🎉
==> Deploying...
==> Using Node version 20.17.0 via /opt/render/project/src/.nvmrc
==> Docs on specifying a Node version: https://render.com/docs/node-version
==> Using Bun version 1.1.0 (default)
==> Docs on specifying a bun version: https://render.com/docs/bun-version
==> Running 'npm run start'
> cb-api@1.0.0 start
> node dist/index.js
query: SELECT * FROM current_schema()
query: CREATE EXTENSION IF NOT EXISTS "uuid-ossp"
query: SELECT version();
DB connected.
Server running on port 10000
==> Timed Out

In my Events tab, the final error message is:

Timed out after waiting for internal health check to return a successful response code at: buddj-api.onrender.com:10000 /health

Have you any idea of what is happening?

Hi there,

We’ve responded to this customer via a private ticket they’ve sent us. Closing this thread out.

Regards,
Mike


Render Support Engineer, MT (UTC-6, UTC-7 in Winter)

Hi, I have answered you through the private ticket :slight_smile: Could I keep this thread open? Maybe the community could help me too and maybe the resolution could help someone else in the future :slight_smile:

I discovered a strange behavior of the deployment interface (where the logs are displayed) and I think it may be related to our problem:

The screenshot below shows that I have set 8081 as the port via my environment variables.

But despite everything, during deployment, the interface still indicates the default port (10000)

Waiting for internal health check to return a successful response code at: buddj-api.onrender.com:10000 /health

While in my logs, at least we can see that it is indeed the env variable 8081 that is taken into account in my server.

DB connected.
Server running on port 8081

What do you think?

I found my mistake: locally my /health route worked because my browser still had the cookie on which I was authenticated. But this route was misconfigured and was not authorized.

Below is my middleware I have updated to reflect my need:

  const isLoggedIn = (req: Request, res: Response, next: NextFunction) => {
    if (
      req.user ||
      req.path.includes("auth/google") ||
      req.path.includes("health")
    ) {
      next();
    } else {
      res.sendStatus(401);
    }
  };