Node.js Deployment in openshift

穿精又带淫゛_ 提交于 2019-12-12 08:49:15

问题


I was trying to deploy a Node.js application to the openshift as in this link here

I understand this code

var http = require('http');

var server = http.createServer(function(req, res) {
    res.writeHead(200);
    res.end('Hello Http');
});
server.listen(3000);

and there is no issue running it locally

$ node server.js // saved as server.js

However, how does this work when I commit this application in openshift? This is very simple code. I have some downloaded code that is a chat application and client-server need to configure to listen on some port (I was using port number 3000 in my localhost).

It works on port number 3000 in localhost but how can I make it to work in Openshift?


回答1:


You need to listen on port process.env.OPENSHIFT_NODEJS_PORT. So something like this should work:

server.listen(process.env.OPENSHIFT_NODEJS_PORT || 3000);

See here for example: Error: listen EACCES on Openshift app




回答2:


Hey the issue with socket.io is that you have that npm package installed local but not in openshift (dependencies don't get pushed). For that you can login thru ssh (look for "Want to log in to your application?" in right menu in openshift control panel, follow instructions and use the ssh connection provided) then login with terminal o Putty, and go to:

cd app-root/repo 

or

cd $OPENSHIFT_REPO_DIR

and then

npm install socket.io

I've used that to install mongoose and other dependencies without trouble. Also you can use

node server.js

from command line to run the site ;)



来源:https://stackoverflow.com/questions/19255186/node-js-deployment-in-openshift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!