0

I'm trying to push my MEAN-Application, which I created locally using express, to OpenShift. For that, I create a new application from the dashboard and add NodeJS as a cartridge. When I then add my Git-Repository-URL (Hosted on BitBucket) and create the application, I get the following error:

Error from the Openshift Dashboard

When I create a new application without entering the repository URL and then pull from Openshift, copy in my Project and Push again, I get a similar error:

Error from Git-Push

It seems to be some problem with port 8080 being unavailable but I cant resolve this myself as I'm new to this and couldn't find a solution on the web, so any help & advice is appreciated.

EDIT: when I say MEAN I actually mean EAN; I don't use MongoDB at the moment.

EDIT 2: after several hours I decided to try Heroku. It also didn't work on the first try but the Log contained far more useful information so I got everything up and running in about an hour (compared to like 4 hours of trying with OpenShift). After that I tried to push the exact same Project I pushed to Heroku to Openshift and got the following, new error:

New Openshift error log

Again, if somebody happens to know a quick fix for this please tell me as I would still like to use OpenShift.

Claas M.
  • 267
  • 3
  • 11
  • The error message says port 8080 is not available. Do you have port 8080 hard-coded in your configuration, or are you using the value of `OPENSHIFT_NODEJS_PORT` like you are supposed to? – Mark B Aug 15 '15 at 15:18
  • Where do I find the configuration? Will it still work locally when I change that and, if not, how can I achieve that without changing it every time I want to deploy? – Claas M. Aug 15 '15 at 16:04

2 Answers2

0

Your NodeJS code should look something like this:

var port = process.env.OPENSHIFT_NODEJS_PORT || 8080;
http.createServer().listen(port);

That will use the value of OPENSHIFT_NODEJS_PORT if it is available, and still use 8080 when you run the application outside of OpenShift. Or you could even set the environment variable OPENSHIFT_NODEJS_PORT=8080 on your local machine to more closely simulate the OpenShift environment.

Note that you should also check the environment variables to get the correct server IP address. See this documentation for more information.

Mark B
  • 183,023
  • 24
  • 297
  • 295
  • the www File was created by Express, which set the port to `normalizePort(process.env.PORT || '3000');`. I changed that to `app.set('port', process.env.OPENSHIFT_NODEJS_PORT || process.env.PORT || 3000); app.set('ip', process.env.OPENSHIFT_NODEJS_IP || "127.0.0.1");` But the Error didn't change. – Claas M. Aug 15 '15 at 17:05
  • It sounds like you may already have a version of your app running that isn't getting shut down for some reason. You could try restarting your app to see if that clears the issue up. Restart instructions are here: https://help.openshift.com/hc/en-us/articles/202399040-How-to-restart-an-application- – Mark B Aug 15 '15 at 17:17
  • I tried that but that wasn't the reason. please see my updated question – Claas M. Aug 15 '15 at 22:06
  • I think you need to SSH into your server and view the logs in `app-root/logs/nodejs.log` to see what is really going on. – Mark B Aug 17 '15 at 14:59
0

What worked for me was the following:

  1. Create App on OpenSHift, leave Repo Url empty for now.
  2. Use git remote add openshift -f <openshift-git-repo-url (ssh://...something)> to add the Openshift-Repo as a remote Repo to your Project.
  3. Use git merge openshift/master -s recursive -X ours to merge the Openshift-Repo into your local Repo and keep your files if conflicts appear.
  4. (And this is the important step) Your main File (bin/www for me) has to look something like this (I tried everything to format this but it just didn't format properly):

    var app = require('../app'); var debug = require('debug')('CTW:server'); var http = require('http');

    /**

    • Get port from environment and store in Express. */ app.set('port', process.env.OPENSHIFT_NODEJS_PORT || process.env.PORT || 3002); app.set('ip', process.env.OPENSHIFT_NODEJS_IP || "127.0.0.1");

    /**

    • Create HTTP server. */

    var server = http.createServer(app);

    /**

    • Listen on provided port, on all network interfaces. */

    server.listen(app.get('port') ,app.get('ip'));

  5. git push openshift HEAD to push it to your Application Repo

As it turns out, I had to set the IP.

All credit goes to this and this questions answers.

Community
  • 1
  • 1
Claas M.
  • 267
  • 3
  • 11