我一直试图解决这个问题几个小时,无休止的谷歌搜索,我尝试启动应用程序,转到网址,看到503服务不可用错误,然后我进入app-root / repo,尝试手动启动server.js,并获得以下内容:
[my-app-url.rhcloud.com repo]\> node server.js
{ [Error: Cannot find module '../build/Release/bson'] code: 'MODULE_NOT_FOUND' }
js-bson: Failed to load c++ bson extension, using pure JS version
Connecting to server
events.js:72
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE
at errnoException (net.js:901:11)
at Server._listen2 (net.js:1039:14)
at listen (net.js:1061:10)
at net.js:1143:9
at dns.js:72:18
at process._tickCallback (node.js:415:13)
at Function.Module.runMain (module.js:499:11)
at startup (node.js:119:16)
at node.js:902:3
这让我感到疯狂,我所做的只是一个简单的api,它在我当地的环境中完美运作。
谢谢。
答案 0 :(得分:2)
此程序的另一个程序或实例已在同一端口上运行。
运行 - sudo netstat -tapen | grep ":<<your given port>>"
然后杀死进程。
然后尝试运行服务器......
由于
答案 1 :(得分:1)
你需要绑定到OPENSHIFT_NODEJS_IP,我知道你只绑定到正确的端口,而不是ip:https://developers.openshift.com/en/node-js-getting-started.html
var ipaddress = process.env.OPENSHIFT_NODEJS_IP || "127.0.0.1";
var port = process.env.OPENSHIFT_NODEJS_PORT || 8080;
var WebSocketServer = require('ws').Server
var http = require('http');
var server = http.createServer(function(request, response) {
console.log((new Date()) + ' Received request for ' + request.url);
response.writeHead(200, {'Content-Type': 'text/plain'});
response.write("Welcome to Node.js on OpenShift!\n\n");
response.end("Thanks for visiting us! \n");
});
server.listen( port, ipaddress, function() {
console.log((new Date()) + ' Server is listening on port 8080');
});
wss = new WebSocketServer({
server: server,
autoAcceptConnections: false
});
wss.on('connection', function(ws) {
console.log("New connection");
ws.on('message', function(message) {
ws.send("Received: " + message);
});
ws.send('Welcome!');
});
console.log("Listening to " + ipaddress + ":" + port + "...");