1

I'm having trouble with my nodejs app deployment. I use Express, MySQL and the basic Express structure for my app. When I open the app URL on openshift I get the 503 error message. On the nodejs.log, I can see this:

Warning: connect.session() MemoryStore is not
designed for a production environment, as it will leak
memory, and will not scale past a single process.
Pipe 8080 is already in use

The application is run with ./bin/www. This is the code I have in that file:

#!/usr/bin/env node

/**
 * Module dependencies.
 */

var app = require('../app');
var debug = require('debug')('adressbook:server');
var http = require('http');

/**
 * Get port from environment and store in Express.
 */

var port =  process.env.OPENSHIFT_NODEJS_PORT || 8080;
app.set('port', port);

/**
 * Create HTTP server.
 */

var server = http.createServer(app);

/**
 * Listen on provided port, on all network interfaces.
 */

server.listen(port);
server.on('error', onError);
server.on('listening', onListening);

/**
 * Normalize a port into a number, string, or false.
 */

function normalizePort(val) {
  var port = parseInt(val, 10);

  if (isNaN(port)) {
    // named pipe
    return val;
  }

  if (port >= 0) {
    // port number
    return port;
  }

  return false;
}

/**
 * Event listener for HTTP server "error" event.
 */

function onError(error) {
  if (error.syscall !== 'listen') {
    throw error;
  }

  var bind = typeof port === 'string'
    ? 'Pipe ' + port
    : 'Port ' + port;

  // handle specific listen errors with friendly messages
  switch (error.code) {
    case 'EACCES':
      console.error(bind + ' requires elevated privileges');
      process.exit(1);
      break;
    case 'EADDRINUSE':
      console.error(bind + ' is already in use');
      process.exit(1);
      break;
    default:
      throw error;
  }
}

/**
 * Event listener for HTTP server "listening" event.
 */

function onListening() {
  //var addr = server.address();
  var addr =  process.env.OPENSHIFT_NODEJS_IP || "127.0.0.1";
  var bind = typeof addr === 'string'
    ? 'pipe ' + addr
    : 'port ' + addr.port;
  debug('Listening on ' + bind);
}
ArtanisAce
  • 957
  • 7
  • 14

1 Answers1

1

The error occurred because the OPENSHIFT_NODEJS_PORT variable was not set on your application's server. This cause the application to use the hardcoded port (8080).

To resolve this, you need to set the OPENSHIFT_NODEJS_PORT environment variable on your application's server. This can be done with:

$ rhc env set OPENSHIFT_NODEJS_PORT=<Value> -a App_Name

where <Value> is the port number you wish to use and App_Name is your application's name.

You can read more about handling environment variables on Openshift here

gnerkus
  • 11,357
  • 6
  • 47
  • 71
  • 1
    Ty @gnerkus! But somehow I cannot set the port number... When I write some port on (by the way, which port should I listen to?), I get the following message: Setting environment variable(s) ... OPENSHIFT_NODEJS_PORT cannot be overridden Actually, if I run rhc env show list -a App_name, nothing is showed... – ArtanisAce Mar 25 '16 at 19:18