我遵循这个免费电子邮件的确切指示(除了我没有存储和使用连接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日志“之后的日志消息。
2017年-06-26T13:11:15.395121+00:00:00“at=error code=H10 desc=”应用程序崩溃“method=GET path="/”host=herokudatabaseprovisioning.herokuapp.com fwd="137.132.242.118“dyno= connect= service= status=503 bytes= protocol=https” 2017年-06-26T13:11:16.634793+00:00:00“at=error code=H10 desc=”应用程序崩溃“method=GET path="/favicon.ico”host=herokudatabaseprovisioning.herokuapp.com fwd="137.132.242.118 dyno= connect= service= status=503 bytes= protocol=https
此外,我还从heroku日志中仔细研究了解决此错误类型的几个堆栈溢出答案,但是所有这些都是通过使用node.js的本机服务器.listen()方法获得的,没有一个涉及如何解决使用mongodb的MongoClient.connect()方法的问题。
如何解决这个问题?我被困在这里面已经两周了,真的。这是github中所有源代码的回购。
发布于 2017-06-26 13:34:57
我刚查过你的package.json。您没有指定脚本参数。这是修改过的版本。还请确保将Procfile重命名为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"
}https://stackoverflow.com/questions/44760783
复制相似问题