0
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.

这是控制台输出:

31-0800 [DEA] OUT 删除 id 为 9dfd06e6-fc10-4207-881a-9557403160b3 的应用程序的崩溃 2014-11-19T03:34:44.31-0800 [DEA] OUT 使用 guid 9dfd06e6-fc10- 停止应用程序实例(索引 0) 4207-881a-9557403160b3 2014-11-19T03:40:44.55-0800 [DEA] OUT 使用 guid 9dfd06e6-fc10-4207-881a-9557403160b3 2014-11-19T003:40:478 启动应用程序实例(索引 0) 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]呃 }); 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 在 Object.Module._extensions..js (module.js:474:10) 2014-11-19T03:40:47.89-0800 [ App/0] Module.load 处的错误 (module.js:356:

4

6 回答 6

1

查看 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

在第 86 行(语法错误)处,您的 app.js 代码显然存在问题。

此外,如果您在推送应用时遇到任何错误,请在 cf 日志中发布详细信息 :)

于 2014-12-27T13:11:37.347 回答
1

看看我在 NodeExpress 中使用 Bluemix 和 MongoDB 的代码 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/

调试您的应用程序的最佳方法是 i) 使用 cf logs --recent ii) 向您的应用程序添加并购服务

问候 Ganesh

于 2014-11-21T02:00:13.097 回答
0

查看日志看起来您的 app.js 在第 86 行存在语法错误,这导致您的错误编译错误。请检查您在 app.js 文件的第 86 行编写的代码。

于 2014-12-29T14:12:11.290 回答
0

您可以通过从 cf 命令行运行来提供更多详细信息:

  cf logs <app_name> --recent 

这应该提供与此错误原因相关的更多信息以供调查。

于 2014-11-19T09:45:15.980 回答
0

您的 cf 日志可以不言自明地捕获此错误:

[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

请更正您的 app.js 代码并再次尝试推送它。

于 2014-12-29T15:22:08.410 回答
0

您发布的 JS 代码中存在语法错误。该错误使您的应用程序崩溃:

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

将此行添加到 app.js 文件的末尾,它应该可以修复它:

}); // end MongoClient.connect()
于 2014-11-20T05:50:04.037 回答