2015-11-18 58 views
0

我瀏覽過與此相關的其他幾個問題,我還沒有找到一個解決方案。當我通過他們的網站登錄打開班次並嘗試打開我的應用程序時,出現503服務不可用錯誤。當我ssh到我的應用程序,並嘗試運行server.js我得到的錯誤:無法獲得的node.js openshift應用程序運行,ERROR:聽EACCESS

events.js:72 throw er; // Unhandled 'error' event ^ Error: listen EACCES at errnoException (net.js:905:11) at Server._listen2 (net.js:1024:19),它只是不斷去像這樣幾行。

我server.js看起來是這樣的:

var express  = require('express'), 
app    = express(), 
bodyParser  = require('body-parser'), 
mongoose   = require('mongoose'), 
meetupsController = require('./server/controllers/meetups-controller'); 

var http = require('http'); 
app.set('port', process.env.OPENSHIFT_NODEJS_PORT || 8080); //testing 
app.set('ip', process.env.OPENSHIFT_NODEJS_IP || '127.0.0.1'); //testing 

//mongoose.connect('mongodb://localhost:27017/mean-demo'); //for local use 

mongoose.connect('mongodb://user_name:[email protected]:port/mean-demo') 
//note: mean-demo is name of the database not my appname. 
//I have replaced mean-demo with my appname (testapp) and it still doesn't work 

app.use(bodyParser.urlencoded({ extended: false })) 
app.use(bodyParser.json()) 

app.get('/', function(req, res){ 
    res.sendfile(__dirname + '/client/views/index.html'); 
}); 

app.use('/js', express.static(__dirname + '/client/js')); 

http.createServer(app).listen(app.get('port'), app.get('ip'), function(){ //testing 
    console.log('Express server listening on port ' + app.get('port')); 
}); 

//REST API 
app.get('/api/meetups', meetupsController.list); 
app.post('/api/meetups', meetupsController.create); 

app.listen(8080, function(){ //was 3000 
    console.log('I\'m Listening...'); 
}) //i have commented these out and the problem still isn't fixed 

我試圖實現這種代碼的各種變化,走動的東西,等等,並沒有什麼作品。我還評論了貓鼬/ mongodb電話,我仍然得到錯誤。順便說一下,這在本地使用mongo DB的本地版本工作。我真的不知道如何解決這個問題,所以一些指導將非常感謝。就像我之前說過的,我已經搜索了各種各樣的stackoverflow,很多人都有這個錯誤,但是似乎沒有解決它們的問題已經修復了我的錯誤。讓我知道你是否需要任何其他信息,我會很樂意提供。

編輯: 所以它現在的工作。我認爲發生的事情是這樣的:我知道EADDRINUSE錯誤是當你訪問一個已經被使用的端口時。我認爲發生的事情是我的應用程序啓動並運行,所以當我試圖運行它時,它試圖運行兩次,並拋出錯誤。我一直在openshift CLI上磨了這麼久,我沒有打擾在網絡瀏覽器上檢查我的應用程序,看它是否工作。多謝你們!

回答

0

嘗試參照本示例代碼(https://github.com/openshift-quickstart/openshift-nodejs-http-and-websocket-example/blob/master/server.js

我想你錯過了什麼是

app.listen(8080, function(){ //was 3000 
    console.log('I\'m Listening...'); 
}) 

應該

app.listen(port, ipaddress, function() { 
    console.log((new Date()) + ' Server is listening on port 8080'); 
}); 

基本上你是正確的端口上偵聽,但是您嘗試可能綁定到所有接口(0.0.0.0)而不是您的node.js端口。

+0

正如你可以從我的第一個電話聽明白了,我做的端口和IP地址 – KPJ

0

你打電話listen兩次。第一個可能成功,但第二個因EACCES而失敗,因爲某個端口上已有監聽。

+0

我評論出來一段時間了,我想什麼都沒有發生調用它。但第二次看,我的錯誤從EACCES到EADDRINUSE。我會去尋找如何解決這個問題(除非你知道如何解決你的問題)。感謝您指點我正確的方向 – KPJ