Last Updated: December 30, 2020
·
3.022K
· otupman

sailsjs - listening on a different IP address

I'm playing around with deploying a simple NodeJS app built with Sails.js. If you're using a single gear, everything will be fine. But if you're using a scalable gear, then you'll probably have some issues and things are rather unhelpful, so here are two quick tips:

It's not Heroku, so process.env.PORT isn't there

The documentation is a little tricky to find, so you need to use process.env.OPENSHIFTNODEJSPORT (obviously). Your config would then look like:

{
    port: process.env.OPENSHIFT_NODEJS_PORT,
    environment: 'production'
}

You're scalable, so you have multiple IPs

And Sails.js is going to try and listen on the IP and port that the HAProxy has setup is listening on. Good luck finding documentation on changing the IP address of Sails.js - it's not :D After much digging, turns out you can supply the config key 'host'. Grrr. You end up with:

{
    port: process.env.OPENSHIFT_NODEJS_PORT,
    host: process.env.OPENSHIFT_NODEJS_IP,
    environment: 'production'
}

Me, I have an environment detection routine that checks to see if it's local, or on OpenShift or on Heroku (in case I switch over to that).

Your mileage may vary.