如何在openshift上部署节点应用程序并运行它?

时间:2017-12-07 19:36:28

标签: node.js deployment openshift

刚刚使用node创建了一个非常简单的hello world应用程序:

var express = require('express');
var app = express();
app.get('/', function (req, res) {
  res.send('Hello World!');
});
var server_port = process.env.OPENSHIFT_NODEJS_PORT || 8080
var server_ip_address = process.env.OPENSHIFT_NODEJS_IP || '127.0.0.1'

app.listen(server_port, server_ip_address, function () {
  console.log( "Listening on " + server_ip_address + ", port " + server_port )
});

并且它可以在我的本地计算机中运行,

将它放在github上并在openshift上部署,pod创建并且服务器正常运行: enter image description here  但当我浏览the route时,我可以在应用程序>>路线菜单中找到它,它说:

Application is not available

The application is currently not serving requests at this endpoint. It may not have been started or is still starting.
I guess I'm using the latest version of openshift since just created an account.

我希望它能向我展示Hello世界!

UPDATE1:

这是我的package.json:

{
  "name": "npmtest",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node index.js"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "express": "^4.16.2"
  }
}

2 个答案:

答案 0 :(得分:0)

您是否在package.json

中配置主文件

并且您可能需要从环境变量动态获取端口检查以下链接以获取openshift示例

https://github.com/openshift/nodejs-ex

答案 1 :(得分:0)

您的应用服务器IP地址必须为0.0.0.0。因此,您要么为其指定环境变量,要么对其进行硬编码。