Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to run code at branch 3.2 #1

Open
shubham-pawar opened this issue Sep 1, 2023 · 1 comment
Open

Unable to run code at branch 3.2 #1

shubham-pawar opened this issue Sep 1, 2023 · 1 comment

Comments

@shubham-pawar
Copy link

Unable to run code at branch 3.2 without following code.

server.listen(parseInt(config.PORT), config.HOST, () => {
  console.log(
    `Express is listening at ${config.SERVER_URL}`,
    `Free Mem: ${os.freemem() / 1024 / 1024}`,
  );
});
  • config.PORT changed to parseInt(config.PORT)
@DarrenSem
Copy link

DarrenSem commented Oct 4, 2023

Agreed, I noticed that I had to use +<port string> but maybe just in case fractions don't work I should use parseInt(<port string>).

https://expressjs.com/en/api.html#app.listen
<http.Server object> = app.listen([port[, host[, backlog]]][, callback])
"This method is identical to Node’s http.Server.listen()..."

https://nodejs.org/api/http.html#class-httpserver = all the example objects use { ... , port: , ... }

And in the 4 places where property names and types are listed -- via searching for port < -- they all say <number>.

.......

The source code makes it even more clear...

https://github.com/nodejs/node/blob/main/lib/internal/validators.js#L410

function validatePort(port, name = 'Port', allowZero = true) {
  if ((typeof port !== 'number' && typeof port !== 'string') ||
      (typeof port === 'string' && StringPrototypeTrim(port).length === 0) ||
      +port !== (+port >>> 0) ||
      port > 0xFFFF ||
      (port === 0 && !allowZero)) {
    throw new ERR_SOCKET_BAD_PORT(name, port, allowZero);
  }
  return port | 0;
}

https://github.com/nodejs/node/blob/main/lib/internal/errors.js#L1667

E('ERR_SOCKET_BAD_PORT', (name, port, allowZero = true) => {
  assert(typeof allowZero === 'boolean',
         "The 'allowZero' argument must be of type boolean.");
  const operator = allowZero ? '>=' : '>';
  return `${name} should be ${operator} 0 and < 65536. Received ${determineSpecificType(port)}.`;
}, RangeError);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants