错误:在Openshift应用程序上收听EACCES

时间:2013-08-11 11:41:33

标签: node.js express openshift

我有以下代码

var express  = require('express')
    , app    = express()
    , server = require('http').createServer(app)
    , io     = require('socket.io').listen(server)
    , connect = require('connect')
    , pg     = require('pg')
    , Client = pg.Client;

// Setup express middleware
app.use(express.static('public'));
app.use(connect.logger());

// Start the server
var port = process.env.OPENSHIFT_INTERNAL_PORT || 8080
    , ip = process.env.OPENSHIFT_INTERNAL_IP || "127.0.0.1";
server.listen(port, ip);

但是,当应用程序自动启动或者我使用节点手动启动时,我总是会收到错误:“警告:错误引发:错误:收听EACCES”

package.json的内容:

{
    "name"        : "test-app",
    "version"     : "0.0.1-1-alpha",
    "description" : "test-app",
    "dependencies": {
        "express"   : "3.1.x",
        "connect"   : "*",
        "socket.io" : "0.9.x",
        "i18next"   : "1.6.x",
        "bower"     : "1.1.1",
        "pg"        : "*"
    },
    "engines": {
        "node" : ">=0.10",
        "npm"  : "1.3.x"
    },
    "scripts": {
        "start" : "node app"
    }
}

我该怎么做才能解决问题?来自openshift的示例server.js没有此问题,但它使用express 2.x。

1 个答案:

答案 0 :(得分:21)

看起来你正在使用旧的环境变量。试试:

// Start the server.
var port = process.env.OPENSHIFT_NODEJS_PORT || 8080  
, ip = process.env.OPENSHIFT_NODEJS_IP || "127.0.0.1";