We are currently running our API server on port 8080, whereas the standard port for HTTP requests is port 80. It would be really inconvenient, and thus bad for user experience, to ask the consumers of our API to attach a port number to the URL for every request.
Therefore, let's change the port that Express is listening on from 8080 to 80 and see what happens. Change the SERVER_PORT environment variable to 80:
SERVER_PORT=80
Then, stop and delete the PM2 application, and run the serve script again. When we run it again, it will initially be successful:
hobnob@hobnob:$ npx pm2 delete 0; yarn run serve
...
[PM2] Done.
┌───────┬──────┬────────┬───┬─────┬─────────┐
│ Name │ mode │ status │ ↺ │ cpu │ memory │
├───────┼──────┼────────┼───┼─────┼─────────┤
│ index │ fork │ online │ 0 │ 0% │ 16.9 MB │
└───────┴──────┴────────┴───┴─────┴─────────┘
However, when we check its status again, PM2 will show you that the application has errored, and it has tried to restart it 15 times before giving up:
hobnob@hobnob:$ npx pm2 status
┌───────┬──────┬─────────┬────┬─────┬────────┐
│ Name │ mode │ status │ ↺ │ cpu │ memory │
├───────┼──────┼─────────┼────┼─────┼────────┤
│ index │ fork │ errored │ 15 │ 0% │ 0 B │
└───────┴──────┴─────────┴────┴─────┴────────┘
We can use the pm2 show <name> command to get information about a particular process:
hobnob@hobnob:$ npx pm2 show index
From the output, we can see that the errors emanating from the application are stored at /home/hobnob/.pm2/logs/index-error.log, so let's take a look at that to see what it says:
hobnob@hobnob:$ tail -n11 /home/hobnob/.pm2/logs/index-error.log
Error: listen EACCES 0.0.0.0:80
at Object._errnoException (util.js:1031:13)
...
The EACCES 0.0.0.0:80 error means that our Node.js process does not have permission to access port 80. This is because, in Linux, ports with numbers below 1024 are deemed privileged, which means they can only be bounded by processes initiated by the root user.