Node.JS SteamBot on openshift - node.js

i´m trying to host my node.js steambot on openshift, i haven´t used it before, so basicly what i´m trying is to Commit a basic "in my eyes, not a server" to their nodejs "hosting".
so, when i commit the files and such, everytime the app starts, it tells me that "port 8080 is not available" and so it can´t start.
idk what is blocking the port so.
what could be the issue ?
regards

The openshift environment is very restrictively firewalled for security reasons. As such you cannot open just any port for your server. The only port you're allowed to open is:
process.env.OPENSHIFT_NODEJS_PORT
If you do testing on your own machine before uploading to openshift, it is useful to check if this environment variable exist or use your own port (like 8080). So you'd typically use do:
var port = process.env.OPENSHIFT_NODEJS_PORT || 8080;
For the outside, you access your openshift server using the URL they gave you at port 80.

OpenShift will routinely check your application to see if it is working correctly. The expectation is that all apps are "web apps", so if you are not listening on the correct port, your app may get rebooted, suspended, or may fail to start correctly.
For your bot to appear to be in good health, you'll need to bind to (process.env.OPENSHIFT_NODEJS_PORT ,process.env.OPENSHIFT_NODEJS_IP), as described in "Run Your Nodejs projects on OpenShift in Two Simple Steps".
Returning a simple HTTP 200 on "/" should be enough to convince OpenShift that your bot (web app) is in good health.

Related

Unable to deploy an application on Heroku due to some port problems

I've been trying to deploy a repository https://github.com/evelynhathaway/triton-poll to heroku, but since I am fairly new to NodeJs, I am unable to detect the problem. But I guess it's due to the port because heroku doesn't use static ports.
Any help would be appreciated.
Thank You in advance.
I looked at the fork and you did a couple of mistakes. I don't have the time to fix, test and get it to run but I can show you how I solved it before.
All the relevant code changes can be found in this commit (different project):
https://github.com/vegeta897/d-zone/commit/63730fd7f44d2716a31fcae55990d83c84d5ffea
The project is divided into a client and server part.
You can see here, https://github.com/vegeta897/d-zone/blob/63730fd7f44d2716a31fcae55990d83c84d5ffea/script/websock.js#L16, how I combined server and client into one. This only works because the static client files are served via http/https and the server uses websocket, no http ws/wss
When you publish a server on Heroku you need to bind to their dynamic port. However when you want to access the web server you do not specify a port. The hostname is automatically translated into an ip-address + port combo. I did this here: https://github.com/vegeta897/d-zone/blob/63730fd7f44d2716a31fcae55990d83c84d5ffea/web/main.js#L44 When deployed on Heroku the socketURL does not contain a port number.
Finally you bind to the server. I did it here https://github.com/vegeta897/d-zone/blob/63730fd7f44d2716a31fcae55990d83c84d5ffea/script/websock.js#L55 and here https://github.com/vegeta897/d-zone/blob/63730fd7f44d2716a31fcae55990d83c84d5ffea/socket-config.js#L30
You also have to make sure that your clients files are built properly and served.

Deploy Create-React-App on a remote Windows Server

I am an inexperienced intern working with a remote Windows Server and React. The Windows Server is running in the company network. I have created a dynamic React website with a NodeJs backend and React Router. I have only ran it on the localhost development server. I want to try to deploy it on the remote Windows Server and give it a custom domain name (Something which can be accessed like servername/myreactapp/).
So far, I have had no success trying to make it work with IIS, even with a web.config file (I get 404 and 500 errors). I am currently making it work by actually running the development server and the nodejs server in the Windows Server, and I access it through the server IP at port 3000.
An improvement would be to be able to access the port through the server name (like servername:3000, instead of the server_ip:3000), but ideally I want to be able to access it like servername/myreactapp/.
Any help would be appreciated. Thank you very much.
The simple solution would be to run your app on port 80 then you will not have to specify the port number.
The best solution would be to set up Nginx on the server and proxy_pass / route to port 3000.
If its running on localhost, which would be port 80, the url would be like http://your_server_name:80, and would be accessible by anyone on the same network, as long as your authentication allows it.

How do ports work in Node.js when on the server?

I'm currently developing a node server locally, and to access it I have the server listen on 8080 and then go to localhost:8080 in the browser. However, how will ports work when I put this project on the internet?
How it works once you "put it on the internet" will be exactly the same. The browser still makes a request to a port (most likely 80 or 443 on the internet), except it will likely be going to a webserver via the internet instead of localhost.
If you want to learn about deploying a node project to a server check out this guide. Basically you need to setup a proxy to sit in front of node to handle all the server stuff like requests and ssl certificates.
I am assuming you mean serve your node.js program and proxy your localhost port to Internet by put this project on the internet. A short answer is that you never host your API on some port on Internet but exposure your local port to a Internet port.
I believe you already know someway to serve a node.js program stably. If not, I really recommend pm2.
If you want to exposure your API to Internet, you first have to get an IP for your local network so that other people can reach your network by this IP. You can also relate it to a domain. Then use softwares like IPfire to manage port mapping. For example, you can map yourIP:8080 to IP ofLocalhostAtLocalNetwork:8080. Then, people can reach your API through yourIP:8080. Or you can simply map yourIP:80 to IPofLocalhostAtLocalNetwork:8080 so that people can reach your API directly by your IP.
Another very popular tool to server and proxy services is nginx. With Nginx, you can easily serve some services and proxy whatever port to whatever service.
You will need to access the global variable "process.env" to dynamically determine the port number when your code is running from a server. The process.env property returns an object containing the user environment.
You may do something like the following to cater to both local and server environments dynamically:
//set port and ip
app.set("port", process.env.PORT || 8080);
app.set("ip", process.env.IP || "0.0.0.0");
app.listen(app.get("port"), app.get("ip"), function (err) {
if (err) {
console.error(err);
return;
} else {
console.info("cicak is running on port " + app.get("port") + ".");
}
});

Hosting Nodejs application without port

I have a nodejs application running on port 3000. I wanted to host it on Linux environment. So I installed nodejs in it. It's working fine but I should specify the port each time.
example: mydomain.net:3000/url_i_want,
How can I avoid this. and also when running my app like that, all users are kind of connected to each others. If one of them disconnect all other users are. If one of them change page all others have there pages changing. Is it because they are all listening to the same port 3000 ? I searched and found that it can be related to PM2 and Nginx. Is it the solution ?
Whenever you load a URL without specifying the port number, the browser defaults to 80, because 80 is the default port number for HTTP.
So if you load http://stackoverflow.com/questions, the browser "converts" it to http://stackoverflow.com:80/questions.
If you don't want a port number to be specified to access your website, your app should be listening on port 80, instead of 3000.
However, it is not recommended for Node apps to directly listen on port 80 (although they very well can).
What you can do is use a front-facing proxy such as nginx, which accepts connections to the host's port 80, and then redirects the request to localhost:3000, where your app is listening.
It is best to ask one question at a time.
As for your second question, unless you are using some sort of "remote syncing" framework, that sort of behavior is unexpected. I would suggest posting a separate question for that issue with more details about it.

Socket server with Node.js and Cloud9 IDE

I am totally new to Cloud9 IDE, so my question amy be silly, but i can't find answer in docs. I want to make client - server application with Node.js + MongoDB as socket server, and client - desktop application which I debug and run on my machine (Cloud9 IDE doesn't support language on which I write it). Looking at Cloud9 IDE I've found it very nice for developing server-side part of my application and may be as hosting solution. But I can't find how to make socket connection from client. For this I need to know IP adress or domain address of my server (I suppose it looks like "https://socialcrm-c9-painkkkiller.c9.io") and port number.
In docs I've found about "use process.env.PORT as the port and process.env.IP as the host in your scripts!" but to connect to server I need they real values! Commands
console.log(process.env.PORT) and console.log(process.env.IP) gives me just "8080" and 0.0.0.0
Using "https://socialcrm-c9-painkkkiller.c9.io" as domain and 8080 as port gives me socket error. So is it possible at all? And if possible how to do it?
Cloud9 forwards port 80 of https://socialcrm-c9-painkkkiller.c9.io to port 8080 in your container. So there is no need to specify the port.
We do also support web sockets and they work in the same way. There's no need to specify another port.
The only thing you need to do is to make sure you are using the environment variables to connect to the right $IP and $PORT when starting your back-end process.
Old question - but I'm struggling with a similar problem. I don't have reputation to add a comment, but this should answer your question about getting the IP into your Cloud9 application.
You can reference process.env.IPto grab the IP... and fwiw, you can reference process.env.PORT to get the port.
Taken from:
https://community.c9.io/t/writing-a-node-js-app/1731

Resources