JavascriptL
JavascriptL

Reputation: 19

Need help in mongodb settings in node app.js file for IBM bluemix deployment

I am trying to create a site and deploy in Bluemix,  using node.js, mongodb (mongolabs) which displays data from mongodb. I created a collection - "caterer", using mongolabs. My app.js is as below :

    var express = require('express'), 
    routes = require('./routes'), 
    cache = require('./routes/cache'), 
    http = require('http'), 
    path = require('path'), 
    mongodb = require('mongodb'), 
    url = require('url'); 
    var mongo = {}; 
    if (process.env.VCAP_SERVICES) { var env = JSON.parse(process.env.VCAP_SERVICES); 
    if (env['mongodb-2.4']) 
    { mongo['url'] = env['mongodb-2.4'][0]['credentials']['uri']; } } 

    //With this as the connector var MongoClient = mongodb.MongoClient; var db = MongoClient.connect(mongo.url, function(err, db) 
    { if(err) { console.log("failed to connect to the database"); } 
    else { console.log("connected to database");}

app.get('/', function(req, res) 
{ mongodb.connect(mongo.url,function(err,conn)
{ var collection = db.get('caterer'); 
collection.find({},{},function(e,details)
{ res.render('index', { "details" : details }); }); }); });

when I push this to jazz hub, this is the error I see in Bluemix logs : BXNUI2034E: Error while getting instances resource. Cloud Foundry issued the following message: "Instance unavailable" See the Troubleshooting topics in the IBM Bluemix Documentation to check service status, review troubleshooting information, or for information about getting help.

This is the console output :

2014-11-19T03:15:57.88-0800 [App/0] ERR at Module.load (module.js:356:32) 2014-11-19T03:15:57.88-0800 [App/0] ERR at Function.Module.runMain (module.js:497:10) 2014-11-19T03:15:57.88-0800 [App/0] ERR at node.js:902:3 2014-11-19T03:15:57.96-0800 [API] OUT App instance exited with guid 9dfd06e6-fc10-4207-881a-9557403160b3 payload: {"cc_partition"=>"default", "droplet"=>"9dfd06e6-fc10-4207-881a-9557403160b3", "version"=>"eab5d831-712a-4e8c-9426-cc01d0fd9a8e", "instance"=>"c5c734ba24ad4109b2befa60b3bc9790", "index"=>0, "reason"=>"CRASHED", "exit_status"=>8, "exit_description"=>"failed to accept connections within health check timeout", "crash_timestamp"=>1416395757} 2014-11-19T03:15:57.96-0800 [API] OUT App instance exited with guid 9dfd06e6-fc10-4207-881a-9557403160b3 payload: {"cc_partition"=>"default", "droplet"=>"9dfd06e6-fc10-4207-881a-9557403160b3", "version"=>"eab5d831-712a-4e8c-9426-cc01d0fd9a8e", "instance"=>"c5c734ba24ad4109b2befa60b3bc9790", "index"=>0, "reason"=>"CRASHED", "exit_status"=>8, "exit_description"=>"failed to accept connections within health check timeout", "crash_timestamp"=>1416395757} 2014-11-19T03:15:57.98-0800 [DEA] ERR Instance (index 0) failed to start accepting connections 2014-11-19T03:34:44.31-0800 [DEA] OUT Removing crash for app with id 9dfd06e6-fc10-4207-881a-9557403160b3 2014-11-19T03:34:44.31-0800 [DEA] OUT Stopped app instance (index 0) with guid 9dfd06e6-fc10-4207-881a-9557403160b3 2014-11-19T03:40:44.55-0800 [DEA] OUT Starting app instance (index 0) with guid 9dfd06e6-fc10-4207-881a-9557403160b3 2014-11-19T03:40:47.88-0800 [App/0] ERR 2014-11-19T03:40:47.88-0800 [App/0] ERR /home/vcap/app/app.js:86 2014-11-19T03:40:47.88-0800 [App/0] ERR }); 2014-11-19T03:40:47.89-0800 [App/0] ERR SyntaxError: Unexpected end of input 2014-11-19T03:40:47.89-0800 [App/0] ERR at Module._compile (module.js:439:25) 2014-11-19T03:40:47.89-0800 [App/0] ERR at Object.Module._extensions..js (module.js:474:10) 2014-11-19T03:40:47.89-0800 [App/0] ERR at Module.load (module.js:356:32) 2014-11-19T03:40:47.89-0800 [App/0] ERR at Function.Module._load (module.js:312:12) 2014-11-19T03:40:47.89-0800 [App/0] ERR at Function.Module.runMain (module.js:497:10) 2014-11-19T03:40:47.89-0800 [App/0] ERR at startup (node.js:119:16) 2014-11-19T03:40:47.89-0800 [App/0] ERR at node.js:902:3 2014-11-19T03:40:47.98-0800 [DEA] ERR Instance (index 0) failed to start accepting connections

Upvotes: 0

Views: 620

Answers (6)

Anand
Anand

Reputation: 645

your cf logs are self explanatory to catch this error:

[App/0] ERR /home/vcap/app/app.js:86 2014-11-19T03:40:47.88-0800 [App/0] ERR }); 2014-11-19T03:40:47.89-0800 [App/0] ERR SyntaxError: Unexpected end of input

Please correct your app.js code and again try to push it.

Upvotes: 0

Manish Kumar
Manish Kumar

Reputation: 387

Looking at the log looks like there is syntax error in your app.js at line 86 which is resulting in compilation error of your error. Please check what code you have written at line 86 in app.js file.

Upvotes: 0

priya2503
priya2503

Reputation: 111

Looking at the logs for cf push appname -recent:

2014-11-19T03:40:47.88-0800 [App/0] ERR /home/vcap/app/app.js:86
2014-11-19T03:40:47.88-0800 [App/0] ERR });
2014-11-19T03:40:47.89-0800 [App/0] ERR SyntaxError: Unexpected end of input

Its clearly seems issue with your app.js code at line number 86(syntax error).

Also,in case if you get any error for pushing your apps,please post details along with cf logs :)

Upvotes: 1

Tinniam V. Ganesh
Tinniam V. Ganesh

Reputation: 2077

Take a look at my code using Bluemix & MongoDB with NodeExpress a) http://gigadom.wordpress.com/2014/08/04/elements-of-crud-with-nodeexpress-and-mongodb-using-enide-studio/ b) http://gigadom.wordpress.com/2014/08/07/spicing-up-a-ibm-bluemix-cloud-app-with-mongodb-and-nodeexpress/

Also the best way to debug your app is i) using cf logs --recent ii) Adding M & A service to your app

Regards Ganesh

Upvotes: 1

Dheeraj
Dheeraj

Reputation: 29

There is a syntax error in the JS code you posted. The error is crashing your app:

2014-11-19T03:40:47.88-0800 [App/0] ERR /home/vcap/app/app.js:86
2014-11-19T03:40:47.88-0800 [App/0] ERR });
2014-11-19T03:40:47.89-0800 [App/0] ERR SyntaxError: Unexpected end of input

Add this line to the end of your app.js file, which should fix it:

}); // end MongoClient.connect()

Upvotes: 0

diwesh
diwesh

Reputation: 294

you can provide more details by running from the cf command line:

  cf logs <app_name> --recent 

This should provide more information related to this error cause for investigation.

Upvotes: 0

Related Questions