Skip to content

[Bug] PORT env var has no fallback, can silently break server startup #116

Description

@sricharan12-hub

Description

The server's listening port has no default value, and the fallback that used to exist is commented out, so a missing PORT env var results in app.listen(undefined, ...).

Details

backend/src/server.js:

const app = express();
// const PORT = process.env.PORT || 5001;
...
app.listen(process.env.PORT, () => {
  console.log("Server listening at port number: " + process.env.PORT);
});

The PORT fallback is commented out, and the raw process.env.PORT is passed straight to app.listen. If PORT isn't set (e.g. a fresh clone using .env.example, which does set PORT=5001, but any environment where it's omitted), Express falls back to picking a random available port with no clear log message, making the failure confusing to diagnose.

Expected

The server should default to a sensible port (e.g. 5001) when PORT is not set, and log the actual port it bound to.

Suggested fix

const PORT = process.env.PORT || 5001;
...
app.listen(PORT, () => {
  console.log("Server listening at port number: " + PORT);
});

I would like to work on this issue. Could you please assign this issue to me?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions