Express PORT issue on Web Service

Hi there. Deploying an existing express app from Heroku, and getting an error about port in use. This is an API that should be responding on port 80/443 depending on HTTPS status.

My code:

const server = http.createServer(app);

server.listen(process.env.PORT, () => {
  logger.info(`Server is listening on port ${process.env.PORT}`);
});

I am not setting an environment variable for PORT, as I believe Render does this automatically right? I am sure this is something trivial - first Render web service, looking to move a bunch of stuff over from Heroku.

Here is the error I am getting:

{
  code: 'EACCES',
  errno: -13,
  syscall: 'listen',
  address: '0.0.0.0',
  port: 443,
  level: 'error',
  app: 'api',
  message: 'listen EACCES: permission denied 0.0.0.0:443',
  stack: 'Error: listen EACCES: permission denied 0.0.0.0:443\n' +
   '    at Server.setupListenHandle [as _listen2] (node:net:1302:21)\n' +
   '    at listenInCluster (node:net:1367:12)\n' +
   '    at Server.listen (node:net:1454:7)\n' +
   '    at /opt/render/project/src/lib/src/server.js:33:12\n' +
   '    at Object.<anonymous> (/opt/render/project/src/lib/src/server.js:36:3)\n' +
   '    at Module._compile (node:internal/modules/cjs/loader:1101:14)\n' +
   '    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)\n' +
   '    at Module.load (node:internal/modules/cjs/loader:981:32)\n' +
   '    at Function.Module._load (node:internal/modules/cjs/loader:822:12)\n' +
   '    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12)\n' +
   '    at node:internal/main/run_main_module:17:47'
}

Hi there,

Thanks for reaching out.

The port specified by your Web service is not the one that is exposed to the public internet. It’s an internal port for your service container.

You’ll likely to currently have an environment variable of PORT set to 443 on your service, which is not permitted as you’ve found. The default is 10000, so you could either set PORT to that, or remove the environment variable altogether (or pick your own PORT, just not 443)

Render Web Services redirect any http (port 80) requests to https (port 443), the proxy then passes the request internally to your container, on the port used by your service, (again, 10000 being default).

Hope that helps, please let us know if you have any more questions.

Kind regards

Alan

1 Like

That did it, thanks!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.