CenterForDigitalHumanities / TinyNode

TinyThings in NodeJS
0 stars 1 forks source link

tinyNode.js normalizePort() is not doing okay #52

Open cubap opened 5 months ago

cubap commented 5 months ago
var port = normalizePort(process.env.PORT || '3002');

This is checking for PORT on .env or assigning "3002". port is supposed to be a <number> so using the String '3002' is already goofy. Even if we cannot trust the .env, the || '3002' (or ??) should be outside the parenthesis.

function normalizePort(val) {
  var port = parseInt(val, 10);

  if (isNaN(port)) {
    // named pipe
    return val;
  }

  if (port >= 0) {
    // port number
    return port;
  }

  return false;
}