expressopenshiftopenshift-cartridge

NodeJS+ Express + MySQL app not running on Openshift


I have a nodejs app that I could succesfully deploy but is not starting. I'm getting this error all the time, when I look on the log files:

Warning: connect.session() MemoryStore is not
designed for a production environment, as it will leak
memory, and will not scale past a single process.
Tue Mar 29 2016 05:48:11 GMT-0400 (EDT): Node server started on 127.8.221.129:8080 ...
Server on port : 8080
Tue Mar 29 2016 05:48:11 GMT-0400 (EDT): Node server stopped.
/var/lib/openshift/56f90f110c1e663f390001df/app-root/runtime/repo/models/user.js:14
    throw err;
    ^
Error: getaddrinfo ENOTFOUND mysql://127.8.221.130:3306/ mysql://127.8.221.130:3306/:3306
    at errnoException (dns.js:26:10)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:77:26)
    --------------------
    at Protocol._enqueue (/var/lib/openshift/56f90f110c1e663f390001df/app-root/runtime/repo/node_modules/mysql/lib/protocol/Protocol.js:141:48)
    at Protocol.handshake (/var/lib/openshift/56f90f110c1e663f390001df/app-root/runtime/repo/node_modules/mysql/lib/protocol/Protocol.js:52:41)
    at Connection.connect (/var/lib/openshift/56f90f110c1e663f390001df/app-root/runtime/repo/node_modules/mysql/lib/Connection.js:123:18)
    at Object.<anonymous> (/var/lib/openshift/56f90f110c1e663f390001df/app-root/runtime/repo/models/user.js:12:13)
    at Module._compile (module.js:413:34)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Module.require (module.js:367:17)
    at require (internal/module.js:16:19)
    at Object.<anonymous> (/var/lib/openshift/56f90f110c1e663f390001df/app-root/runtime/repo/routes/users.js:3:13)
    at Module._compile (module.js:413:34)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Module.require (module.js:367:17)

This is MySQL connection code (password is hidden, but I use the one provided by the MySQL cartridge, as well as the user):

var connection = mysql.createConnection({
host     : 'mysql://' + process.env.OPENSHIFT_MYSQL_DB_HOST + ':' + process.env.OPENSHIFT_MYSQL_DB_PORT + '/',
user     : 'adminbL38x6k',
password : '********',
database : 'addressbook'
});

 connection.connect( function(err){
if (err){ 
    throw err;
}
else {
    console.log('Connected');
}
 });

I'm using PHPmyAdmin too, for creating tables/managing database. Any ideas? I'm pretty desperate... Thank you!


Solution

  • The connection error shows two connection strings (ENOTFOUND mysql://127.8.221.130:3306/ mysql://127.8.221.130:3306/:3306) and according to the mysql node.js driver's documentation, the host and port should be provided separately or in a single connection string, I recommend rather:

    var connection = mysql.createConnection({
    host     : process.env.OPENSHIFT_MYSQL_DB_HOST,
    port     : process.env.OPENSHIFT_MYSQL_DB_PORT,
    user     : 'adminbL38x6k',
    password : '********',
    database : 'addressbook'
    });
    

    ...or the connection string way:

    var connection = mysql.createConnection(process.env.OPENSHIFT_MYSQL_DB_URL + 'addressbook');