Getting & ldquo; failed to accept connection & rdquo; while deploying my app in bluemix

advertisements

Hi Am facing "failed to start accepting connection" error while pushing or deploying my app to bluemix. Can any help me in that.... my code snippet as given below:

var express     = require('express');
app         = express();
var ibmbluemix  = require('ibmbluemix')
var ibmdb = require('ibm_db');
var http = require('http');
var url = require('url');
var logger = ibmbluemix.getLogger();
var PORT = (process.env.VCAP_APP_PORT || 8000);
var HOST = (process.env.VCAP_APP_HOST || 'localhost');
var queryData = null;
var serviceName = 'SQLDB';

if (process.env.VCAP_SERVICES) {
   var env = JSON.parse(process.env.VCAP_SERVICES);
   db2 = env['sqldb'][0].credentials;
}
else{
   console.error("INFORMATION FOR DB CONNECTION NOT FOUND");
}

var dbConnection = "DRIVER={DB2};DATABASE=" + db2.db + ";UID=" +  db2.username + ";PWD=" + db2.password + ";HOSTNAME=" + db2.hostname +  ";port=" + db2.port;
console.log("Connection String: " + dbConnection);

http.createServer(function(request, response) {
    console.log('Creating the http server');
    ibmdb.open(dbConnection, function(err, conn) {
        if (err) {
            response.send("error occurred " + err.message);
        }
        else {
            console.log('before select');
            conn.query("SELECT FULL_NAME,  PASSWORD,  SHORT_ID FROM USER02130.USER_DETAILS", function(err,  rows, moreResultSets) {
                console.log('Connection result error '+err);
                console.log('no of records is '+rows.length);
                response.writeHead(200, { 'Content-Type': 'application/json'});
                response.write(JSON.stringify(rows));
                response.end();
            });
        }

}).listen(PORT, HOST);

Can anyone help me in this, Thanks in advance


There are a few syntactical errors in your snippet (missing closing brackets etc). Try using this instead:

var express     = require('express');
app = express();
var ibmbluemix  = require('ibmbluemix')
var ibmdb = require('ibm_db');
var http = require('http');
var url = require('url');
var logger = ibmbluemix.getLogger();
var PORT = (process.env.VCAP_APP_PORT || 8000);
var HOST = (process.env.VCAP_APP_HOST || 'localhost');
var queryData = null;
var serviceName = 'SQLDB';

if (process.env.VCAP_SERVICES) {
   var env = JSON.parse(process.env.VCAP_SERVICES);
   var db2 = env['sqldb'][0].credentials; // missed declaration
}
else{
    console.error("INFORMATION FOR DB CONNECTION NOT FOUND");
}

var dbConnection = "DRIVER={DB2};DATABASE=" + db2.db + ";UID=" +  db2.username + ";PWD=" + db2.password + ";HOSTNAME=" + db2.hostname +  ";port=" + db2.port;
console.log("Connection String: " + dbConnection);

http.createServer(function(request, response) {
    console.log('server request'); // does not create a server on every request
    ibmdb.open(dbConnection, function(err, conn) {
        if (err) {
            response.send("error occurred " + err.message);
        }
        else {
            console.log('before select');
            conn.query("SELECT FULL_NAME,  PASSWORD,  SHORT_ID FROM USER02130.USER_DETAILS", function(err,  rows, moreResultSets) {
                console.log('Connection result error '+err);
                console.log('no of records is '+rows.length);
                response.writeHead(200, { 'Content-Type': 'application/json'});
                response.write(JSON.stringify(rows));
                response.end();
            });
        }
    }) // missed closing brackets
}).listen(PORT, HOST);

console.log("Server running at "+HOST+" on port "+ PORT);

Node.js is very easy to set up locally, get it here. Running it locally can help you identify many problems, such as syntactical error.

Hope it helps!