Heroku不会运行mongolab app

时间:2017-06-26 13:22:19

标签: heroku mlab

我按照this freecodecamp post的确切说明操作(除了我没有存储和使用连接URI .env变量),但该应用的网页显示了' 应用程序中发生错误,无法提供您的页面。如果您是应用程序所有者,请查看日志以获取详细信息。'

以下是我的app.js中的内容,我绝对肯定用户名和密码是正确的,格式正确。



//lets require/import the mongodb native drivers.
var mongodb = require('mongodb');

//We need to work with "MongoClient" interface in order to connect to a mongodb server.
var MongoClient = mongodb.MongoClient;

// Connection URL. This is where your mongodb server is running.

//(Focus on This Variable)
var url = 'mongodb://user1:123456@ds139959.mlab.com:39959/url-shortener';
//'mongodb://user1:123456@ds139959.mlab.com:39959/url-shortener';     
//(Focus on This Variable)

// Use connect method to connect to the Server
  MongoClient.connect(url, function (err, db) {
  if (err) {
    console.log('Unable to connect to the mongoDB server. Error:', err);
  } else {
    console.log('Connection established to', url);

    // do some work here with the database.

    //Close connection
    db.close();
  }
});




这是我键入" heroku logs"

后的日志消息
  

2017-06-26T13:11:15.395121 + 00:00 heroku [router]:at = error code = H10   desc =" App崩溃" method = GET path =" /"   主机= herokudatabaseprovisioning.herokuapp.com   request_id = f2f3d85e-154c-4169-8c8c-9a1f4bdee05c fwd =" 137.132.242.118"   dyno = connect = service = status = 503 bytes = protocol = https

     

2017-06-26T13:11:16.634793 + 00:00 heroku [router]:at =错误代码= H10   desc =" App崩溃" method = GET path =" /favicon.ico"   主机= herokudatabaseprovisioning.herokuapp.com   request_id = 01d79a9d-0088-4dac-b582-79e08c8e0858 fwd =" 137.132.242.118   dyno = connect = service = status = 503 bytes = protocol = https

另外,我已经仔细检查了一些堆栈溢出答案,这些答案是从heroku日志中解决这个错误类型的,但所有这些都来自于使用node.js'本地服务器.listen()方法,没有解决过如何解决使用mongodb MongoClient.connect()方法

的问题

如何解决这个问题?我认真地坚持了两个星期。 这是github中完整源代码的the repo

1 个答案:

答案 0 :(得分:0)

我刚刚浏览了你的package.json。你没有指定你的脚本参数。这是一个修改过的版本。还要确保将proc文件重命名为Procfile。

{
    "name": "trial",
    "version": "1.0.0",
    "description": "Test for Hesington",
    "scripts": {
        "start": "node app.js"
    },
    "main": "app.js",
    "dependencies": {
        "mongodb": "^2.2.29"
    },
    "devDependencies": {},
    "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1"
    },
    "author": "",
    "engines": {
    "node": "6.10.3",
        "npm": "5.0.2"
    },
    "license": "ISC",
    "repository": {
        "type": "git",
        "url": "git+https://github.com/hesingon/FFCdbprovision.git"
    },
    "bugs": {
        "url": "https://github.com/hesingon/FFCdbprovision/issues"
    },
    "homepage": "https://github.com/hesingon/FFCdbprovision#readme"
}