0

While deploying node.js with socket.io on Openshift fails with below error : "Waiting for application port (8080) become available ... remote: Application 'meraapp' failed to start (port 8080 not available)"

I want to use this server to connect to my android chat app. below is my server.js

var express = require('express')
  , routes = require('./routes')
  , user = require('./routes/user')
  , path = require('path')
  , app = express()
  , http = require('http').Server(app)
  , io = require('socket.io')(http);


app.set('port', process.env.OPENSHIFT_NODEJS_PORT || 8080);
app.set('ipaddr', process.env.OPENSHIFT_NODEJS_IP);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));

// development only
if ('development' == app.get('env')) {
  app.use(express.errorHandler());
}

io.on('connection', function(socket){
 console.log('a user connected');
 socket.on('new_message', function(data){
 console.log('new_message' + JSON.stringify(data));
 io.emit('new_message', data);
 });
 socket.on('login', function(data) {
console.log('login :' +  data);
});
socket.on("disconnect", function() {
console.log("disconnect");
});
});

app.get('/', routes.index);
app.get('/users', user.list);

http.listen(app.get('port'), app.get('ipaddr'), function() {
console.log('Socket.IO chat server listening on  IP: ' + app.get('ipaddr')  + ' and port ' + app.get('port'));
});

please note that I have seen this question : Application failed to start (port 8080) not available but the solutions did not work in my case.

Community
  • 1
  • 1
srv_sud
  • 647
  • 1
  • 9
  • 26

2 Answers2

1

On OpenShift Online (v2), websocket support is available - however, currently, it's only available via these non-standard ports: 8000 8443

You won't need to make any server-side changes to your code, as OpenShift's load-balancer will expose your application on ports 80, 443, 8000, and 8443. But, your client-side code will need to connect to your server using port 8000 or 8443 in order to get full support for websockets.

https://blog.openshift.com/10-reasons-openshift-is-the-best-place-to-host-your-nodejs-app/#websockets

ʀɣαɳĵ
  • 1,992
  • 1
  • 15
  • 20
  • I tried the tips from the link you suggested. but still struggling with the error. Some links suggest that this might occur due to some modules missing or some javascript errors. I am revisiting my code to check those pitfalls. – srv_sud Apr 19 '16 at 04:57
0

Port 8080 must be used by some other application. Try to release the port 8080 and then try to run your application. to find which application using which port refer below url How do I find which application is using up my port

Community
  • 1
  • 1
  • dear ashish. the problem is not as simple and direct as it looks by the error shown in logs. Please go through this link http://stackoverflow.com/questions/31511724/application-failed-to-start-port-8080-not-available and let me know if you have some solution for my issue. :) and thanks for your quick response. – srv_sud Apr 13 '16 at 19:44