Reputation: 461
I am following the exact instructions from this freecodecamp post(except that I haven't stored and used the connection URI .env variable), yet the app's webpage shows 'An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details.'
Below is what is in my app.js, and I am absolutely positive that the username and password are correct and of the correct format.
//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();
}
});
This is the log messages after i typed "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
Also, I've scrutinized a few stack overflow answers addressing this error type from heroku logs, yet all those are arised from using node.js' native server .listen()
method, none of those addressed about how to resolve the issue of using mongodb's MongoClient.connect()
method
How to resolve this? I have been stuck in this for 2 weeks, seriously. This is the repo of the whole source codes in github.
Upvotes: 0
Views: 889
Reputation: 76
I just went through your package.json . You didnt specify your scripts parameter. Here's a modified version. Also be sure to rename your procfile to 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"
}
Upvotes: 0