Heroku不会运行mongolab应用程序

问题描述 投票:0回答:1

我遵循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:[email protected]:39959/url-shortener';
//'mongodb://user1:[email protected]: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 crashed”method = GET path =“/”host = 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 = error code = H10 desc =“App crashed”method = GET path =“/ favicon.ico”host = 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()method的问题

怎么解决这个?我认真地坚持了两个星期。这是github中整个源代码的the repo

heroku mlab
1个回答
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"
}
© www.soinside.com 2019 - 2024. All rights reserved.