Say "Hello World!" in Openshift with Node.js
I created an application in Openshift and created a local git repository on my computer. I want to change the default welcome page here: http://nodejs-j4nos.rhcloud.com:3000 and just say Hello world like this tutorial says.
So, I removed from the local repo index.html and modified the server.js pasted in this code below. And do it and push it. I get long approval that they've accepted my commit.
If I understand well, I don't need to stop node and start it again, but Openshift does it for me. But since you can't see Hello World can't see when the link is open in the browser ( http://nodejs-j4nos.rhcloud.com:3000 ) why?
var express = require('express');
var app = express();
app.get('/', function (req, res) {
res.send('Hello World!');
});
var server = app.listen(3000, function () {
var host = server.address().address;
var port = server.address().port;
console.log('Example app listening at http://%s:%s', host, port);
});
remote: Git Post-Receive Result: success
remote: Activation status: success
remote: Deployment completed with status: success
To ssh://5556b4c4fcf9336abf0000de@nodejs-j4nos.rhcloud.com/~/git/nodejs.git/
and here is the tree structure, express
specified
Based on this SO answer, I tried to change the script but didn't help:
var express = require('express');
var app = express();
app.set('port', process.env.OPENSHIFT_NODEJS_PORT || 8080);
app.set('ip', process.env.OPENSHIFT_NODEJS_IP || '127.0.0.1');
http.createServer(app).listen(app.get('port'), app.get('ip'), function(){
console.log('Express server listening on port ' + app.get('port'));
});
app.get('/', function (req, res) {
res.send('Hello World!');
});
source to share
Link works now: http://nodejs-j4nos.rhcloud.com Correct script to show "Hello world!" this is
var http = require('http');
var express = require('express');
var app = express();
app.set('port', process.env.OPENSHIFT_NODEJS_PORT || 8080);
app.set('ip', process.env.OPENSHIFT_NODEJS_IP || '127.0.0.1');
http.createServer(app).listen(app.get('port'), app.get('ip'), function(){
console.log('Express server listening on port ' + app.get('port'));
});
app.get('/', function (req, res) {
res.send('Hello World!');
});
And here's the proof:
Thanks for this: Deployed Node application for OpenShift is successful, OpenShift still shows the default page and this question: Node.js Deployment in shear virtual
And now you have to write to the /app-root/repo
command $ node server.js
and if there is something wrong with the script it will point right there
source to share
Found my notes on using OpenShift with Node: The openshift system has some integrated controls to support its "cog system" useful for managing the opening application and environment change.
gear control your application (start, stop, restart, etc)
or deps with --cart (gear start --cart mysql-5.1)
tail_all tail all log files. This command displays the last entries
in your log files as they are written. You can hit
<ctrl>-c to exit this command.
export list available environment variables
rm remove files / directories
ls list files / directories
ps list running applications
kill kill running applications
mysql interactive MySQL shell
mongo interactive MongoDB shell
psql interactive PostgreSQL shell
quota list disk usage
The transmission system has additional commands. OpenShift Gear Control, Assortment of transmission utilities:
TEAMS:
build Run the build steps
deploy Run the deploy steps
help Display global or [command] help documentation.
postreceive Run the git postreceive steps
prereceive Run the git prereceive steps
reload Reload a cart
remotedeploy Run the remotedeploy steps
restart Restart a cart
restore Restore an application
snapshot Snapshot an application
start Start the gear/cart
status Get the status for a cart
stop Stop the gear/cart
Will any of these things help you stop and restart the transmission? I would start with a simple command "equipment". I don't remember if Express was downloaded via NPM or is it now native from node? At one time this was an NPM installation. Those who don't get into Openshift.
What is the directory tree structure in openshift nodejs server?
root
\ app-root
\ data
\ repo <- - the working files for web content end up here.
\ runtime
\ git
\ nodejs
In openshift options, dependencies are not pushed. To do this, you can login via ssh and navigate to: cd app-root/repo
or cd $OPENSHIFT_REPO_DIR
and thennpm install tool_of_choice
source to share
I read this, maybe you should be using a port over 15000:
https://help.openshift.com/hc/en-us/articles/202185874-I-can-t-bind-to-a-port
source to share