Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Portable node.js across Heroku and OpenShift
* Get port from environment and store in Express.
* Heroku uses 'port' environment variable
* OpenShift uses 'OPENSHIFT_NODEJS_PORT' environment variable
* locally 8090 will be used
var server_port = process.env.PORT || process.env.OPENSHIFT_NODEJS_PORT || 8090;
var server_ip_address = process.env.OPENSHIFT_NODEJS_IP;
* Store in Express.
app.set('port', server_port);
* Create HTTP server.
var server = http.createServer(app);
* Start the app on the specific interface (if specified) and port.
* On heroku and locally 'server_ip_address' will be undefined
* On OpenShift it will be defined
server.listen(server_port, server_ip_address, function () {
console.log('%s: Node server started on %s:%d ...',
Date(, server_ip_address, server_port);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.