Node.js chat server running on "cloud9-ide" is listening but not able to connect using client - node.js

Chat server is listening to the port, below snippet is from console log.
Your code is running at https://mynodetest-someone.c9.io.
Important: use process.env.PORT as the port and process.env.IP as the host in your scripts!
debugger listening on port 15454
info - socket.io started
Chat server listening at 0.0.0.0:4000
When trying to connect through browser: eg: "localhost:4000", connection is refused(Error code: ERR_CONNECTION_REFUSED)
Can some one help how to fix this issue?.
Note:
I have tried listening on "127.0.0.1" and given original IP address in the network.

You can access the server using the URL that cloud9 provides for that specific server/project.
Use process.env.PORT as the port and process.env.IP as the host for you application and access your app using your project name - username. Should be something like https://mynodetest-someone.c9.io.
From the c9 page:
Important: use process.env.PORT as the port and process.env.IP as the host in your scripts!

Related

how to allow access to port on AWS

I am trying to connect to my development port port 3000 on aws but it is not working. I have currently configured my domain with the instance and it is working fine but I cannot access port 3000 and get ERR_EMPTY_RESPONSE
The security group setting is as below
As you can see, I have opened up my mongo port 27017 and 3000 which is my node server port
As you can see here, it is listening at port 3000. I set it to print out the exact port that is being listened.
When I go netstat -natlp the following shows
port 3000 is currently listening.
I have followed all the instructions and suggestions but it is still not working for a weird reason. The server I use is Asia(Seoul) server.
Am I missing something here?

How do I set node app to run on a static port number on heroku?

my node app runs on port 8083 locally. when I push to heroku, how can I configure the service to run on the same port?
You cannot do it. Your code should listen on the port that you have in the PORT environment variable passed to you by the Heroku server that you can access as process.env.PORT and Heroku will listen on the outside on port 80 for HTTP and 443 for HTTPS.
See the docs:
https://devcenter.heroku.com/articles/runtime-principles
In particular:
https://devcenter.heroku.com/articles/dynos#web-dynos
https://devcenter.heroku.com/articles/http-routing
https://devcenter.heroku.com/articles/ssl-endpoint
Correct example:
// Get the port:
const PORT = process.env.PORT || 3000;
// Listen on the port:
app.listen(PORT, () => console.log('Listening on', PORT));
The default (3000 in this example) is for situations when you run it outside of Heroku (like for testing). When it is run on Heroku it should always listen on the port provided by Heroku. If it listens on some other port then Heroku will not proxy the traffic to your app correctly.

How get second port from Heroku for websocket

I'm using Heroku to deploy my nodejs game.
Everything works fine but the websockets on my game won't work when I deploy it to Heroku.
Heroku gives me 1 available port (in the var port).
Is there a way to get a second port where my socket can listen to?
If I try to set the socket to the same port as the app.listen, it tells me the port is already in use.
var port = process.env.PORT || 8080;
app.listen(port);
socket = io.listen(8000);

Node.js socket app on openshift

I'm trying to deploy a simple node.js socket app on OpenShift.
First I tried setting up the listener as:
var server = net.createServer(newSocket); //newSocket is a listener method
var port = 8888;
server.listen(port);
and this causes:
Error: listen EACCES
Then I researched a bit and learned that you need to listen using OPENSHIFT_NODEJS properties and set the listener like this:
var server = net.createServer(newSocket);
var ipaddr = process.env.OPENSHIFT_NODEJS_IP || "127.0.0.1";
var port = process.env.OPENSHIFT_NODEJS_PORT || 8888;
server.listen(port, ipaddr);
Now the app is started at: 127.6.253.1:8080 - however when I try to telnet it using my OpenShift app url and 8080 I get server timeout.
If you have experience with the similar situation let me know.
The code of the app I'm trying to make it work on OpenShift is at https://github.com/denimf/NodeChat
The internal port for the OpenShift app is 8080, but it is exposed externally on port 80 at the URL specified in your control panel. You can also see the app URL in the console by doing:
echo $OPENSHIFT_APP_DNS
Most of the node.js web hosting services don't support socket listener. I solved my problem by hosting the Node app on a dedicated virtual machine.

Node.js + Express only work on port 3000 on test server

On Local Test it work. on different port (3001, 8080)
But on Test Server (Azure)
I run 2 instance of Node App on same machine
$ node api1/index.js (on port 3000)
$ node api2/index.js (on port 3001)
and
$ node api1/index.js (on port 3001)
$ node api2/index.js (on port 3000)
But it only works on port 3000.
How do I set different port in Express?
Now, I've changed at app.listen(3001) on index.js and it doesn't work.
Often cloud platforms set an environment variable that contains the port they want you to stick your app on. I don't have any experience with Azure... See the answer here: How to run a node.js server on Azure?
Specifically:
var port = process.env.port
Most cloud providers in my experience don't let you play on other ports. You can always specify a localhost port too, though by doing this:
var port = process.env.port || 3001 //(or whatever)
app.listen(port);
this way if process.env.port is undefined (which it will be in your dev environment) you fallback to 3001.
Make sense?

Resources