Socket server with Node.js and Cloud9 IDE - node.js

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

Related

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.

Node.JS SteamBot on openshift

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.

Connecting to websocket server from external network

I'm not sure whether to ask this question on a programming forum or linux administration forum as it involves both programming with web sockets and server admin. Basically I am trying to follow this guide "http://41j.com/blog/2014/12/simple-websocket-example-golang/". I have a centos basic server that has a static IP and I've port forwarded it to ports 22 and 80 (ssh and http). I can compile and run the server app fine, but i cannot connect the client. I'm currently out of ideas since I've never messed with networking before. I read somewhere that html5 websockets go through ports 80 and 443 when given an external IP. What I want is to start the server app on port say something like 1445 and then lets pretend my external IP is 244.214.21.44 and then have client connection string look like 'ws//244.214.21.44:1445/echo'. What am I missing, do I need to install apache or something?
Thanks for reading.

TCP server won't work on Openshift NodeJS

I've used the openshift-cartridge-tcp-endpoint cartridge to try and make a TCP server which I can access from a desktop application.
I've set it up on a scaleable application and I can see the OPENSHIFT_NODEJS_PORT_TCP and OPENSHIFT_NODEJS_PROXY_PORT_TCP values when I list the environment variables using 'export' when ssh'd into my application.
The problem is, when I do 'rhc ssh APP_NAME oo-gear-registry all', no port is listed over which I can access my TCP application and when I try to access the application over the port given by the HTTP server, it does not connect. Do I have to take additional steps to make the port show up and be accessible?
It looks like that cartridge is over 2 years old, and probably doesn't work with the current version of OpenShift Online, as it only exposes port 8080 publicly and uses an HTTP/WS reverse proxy, so only http or web services connections would work. You might try logging an issue with the cartridge's creator here (https://github.com/Filirom1/openshift-cartridge-tcp-endpoint/issues) and ask them if it still works or not.

How do IP addresses work on a VPS? Routing a domain name to Node.JS

This is an absolute newb question. But I'm buying my first VPS for the reason that I want to install and start creating applications in Node.JS.
I can't visualise in my mind how the server works and where all of the applications such as Apache, Node.JS and PHP sit. I'm so used to a GUI.
I want www.mydomain.com to point to node.JS on my server, let's say Node is listening to port 8080. Now I know that HTTP defaults to port 80 of the IP address, so I can't use that. How do I set the domain up to resolve at www.mydomain.com:8080 - I read this wasn't possible...
My brain is melting.
Thanks :)
You just point the domain to your ip address as you normally do. The issue you will have it that HTTP default to port 80, so either you manually add the port at the end of the host to get to the page or you setup Apache to proxy specific urls to 8080, which gets some of your Node stuff appearing to work under 80.
If you aren't using Apache for anything you can also have your Node app bind to port 80. You will probably need to setup authbind or something to give your node app permission to bind to port < 1024.

Resources