说"Hello World!"在Openshift中使用Node.js [英] Say 'Hello World!' in Openshift with Node.js

查看:103
本文介绍了说"Hello World!"在Openshift中使用Node.js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Openshift中创建了一个应用程序,并在计算机上创建了本地git repo.我想在此处更改默认的欢迎页面: http://nodejs-j4nos.rhcloud.com:3000 ,然后以教程中的说法告诉Hello World.

I created an app in Openshift and created a local git repo on my computer. I want to change the default welcome page here: http://nodejs-j4nos.rhcloud.com:3000 and just tell Hello world as this tutorial say.

因此,我从本地存储库中删除了index.html,并修改了server.js,粘贴在下面的这段代码中.并提交并推送.我得到了他们的长期认可,他们接受了我的承诺.

So I removed from local repo the index.html, and modified server.js, pasted in this code below. And commit, and push. I get a long approval, that they accepted my commit.

如果我理解得很好,则不必停止节点并重新启动它,但是Openshift会为我执行此操作.但正如您看到的那样,当在浏览器中打开链接时( http://nodejs -j4nos.rhcloud.com:3000 )为什么?

If I good understand I do not have to stop node and start it again, but Openshift do it for me. But as you can see no Hello World is able to see, when open link in 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/

这是树结构,其中列出了express

and here is the tree structure, express is listed

基于这样的答案,我试图修改脚本,但没有帮助:

Based on this SO answer I tried to modify script, but does not helped:

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!');
});

推荐答案

链接现在可以使用: http://nodejs-j4nos.rhcloud.com 显示"Hello world!"的正确脚本.是

Link is working now: http://nodejs-j4nos.rhcloud.com The right script to show "Hello world!" 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!');
});

这是证明:

为此:已成功将节点应用程序部署到OpenShift,OpenShift仍显示默认页面 和这个问题: Node.js在openshift中的部署

Thanks for this: Deployed Node app to OpenShift successfully, OpenShift still shows default page and this question: Node.js Deployment in openshift

现在您应该可以在/app-root/repo $ node server.js命令中编写命令,如果脚本有问题,它将在此处指示

And you should now that you can write in /app-root/repo the $ node server.js command, and if something wrong with script, it will indicate right there

这篇关于说"Hello World!"在Openshift中使用Node.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆