Node.js Deployment deployment

I tried to deploy the Node.js application in 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 no problems with local launch

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

However, how does it work when I commit this application in openshift? This is a very simple code. I have downloaded code, which is a chat application, and the client server needs to configure listening on some port (I used port number 3000 in my local host).

It works with port number 3000 in localhost, but how can I get it to work in Openshift?

+6
source share
2 answers

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

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

See here for example: Error: listening to EACCES in an Openshift application

+9
source

Hey, the problem with socket.io is that you have the npm package installed locally, but not in openshift (dependencies are not clicked). To do this, you can log in via ssh (find “Do you want to log in to your application?” In the right menu in the control panel with an opening branch, follow the instructions and use the provided ssh connection), then log in with o Putty and go to:

 cd app-root/repo 

or

 cd $OPENSHIFT_REPO_DIR 

and then

 npm install socket.io 

I used this to install mongoose and other dependencies without problems. You can also use

 node server.js 

from the command line to start the site;)

+2
source

Source: https://habr.com/ru/post/955517/


All Articles