NodeJS application on OpenShift giving 503 error

If you’ve got a Node.js application running on OpenShift, chances are at some point you’ve seen a 503 error when deploying the application.

The OpenShift FAQ tells us to take a look at the log files in this situation.

Looking at the log files for my application, I was getting the following error:

> node app.js

        throw arguments[1]; // Unhandled 'error' event
Error: listen EACCES
    at errnoException (net.js:670:11)
    at Array.0 (net.js:756:28)
    at EventEmitter._tickCallback (node.js:190:38)
npm info application-name@0.0.1 Failed to exec start script
npm ERR! application-name@0.0.1 start: `node app.js`
npm ERR! `sh "-c" "node app.js"` failed with 1

This error (in OpenShift terms) seems to mean that the server is not listening on the correct port / address.

This can be fixed by ensuring that the Node.js server is configured to use the process.env.OPENSHIFT_NODEJS_PORT and process.env.OPENSHIFT_NODEJS_IP, for example:

app.listen(process.env.OPENSHIFT_NODEJS_PORT || 8080,

Specifically, I’ve found that when getting a 503, it means that you haven’t specified an IP address. On OpenShift, Node.js apps seem to need to be supplied an IP address to bind to, a port is not sufficient.