2017-06-26 82 views
0

我下面從this freecodecamp post確切的指令(除了我沒有存儲和使用的連接URI .ENV變量),但在應用中出現的應用程序的網頁上顯示「錯誤,您的頁面無法投放。如果您是應用程序所有者,請查看日誌以獲取詳細信息。'的Heroku將無法運行mongolab應用

下面是我的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記錄」

2017-06-26T13:11:15.395121 + 00:00的Heroku [路由器]:=在錯誤代碼= H10 DESC = 「應用程序崩潰」 方法= GET路徑= 「/」 宿主 = herokudatabaseprovisioning.herokuapp.com REQUEST_ID = f2f3d85e-154C-4169-8c8c-9a1f4bdee05c FWD = 「137.132.242.118」 DYNO =連接=服務=狀態= 503字節=協議= 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 =連接=服務=狀態= 503字節=協議= HTTPS

另外,我仔細檢查幾個棧溢出回答解決這個錯誤類型從heroku日誌,但所有這些都來自使用node.js的本地服務器.listen()方法,這些都沒有解決如何解決使用mongodb的方法MongoClient.connect()方法

如何解決這個問題?我一直堅持2周,認真。 這是github的整個源代碼的the repo

回答

0

我剛剛通過了你的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" }

+0

哦,我明白了。我只是將文件更改爲'web:node app.js',但它仍然沒有工作:/ – Darius

+0

您的package.json文件也有問題。我修正了他們,並編輯了我以前的帖子。 – Boxpositron

+0

非常感謝,我已經設法從命令'heroku logs --tail'輸出期望的日誌消息,在這種情況下'2017-06-27T02:38:58.857556 + 00:00 app [web .1]:連接建立到mongodb:// user1:[email protected]:39959/url-shortener'。但是,當我用命令'heroku open'打開應用程序頁面時,我仍然看到顯示應用程序錯誤。這是正常的,因爲我沒有提供任何HTML文件? – Darius