NodeJs Application on Aws Ubuntu is running on ipv6 - node.js

While running nodejs with express application on AWS ubuntu 16.04, it's running on tcp6 and due to this, i'm unable to access my application.
see below screenshot.
after adding IP address while creating server, it's giving below error.
I'm new to linux, so I do not know how to resolve it. please suggest.

You need to explicitly provide an IP to bind to in Node.js, otherwise it binds to IPv6. Documented here: https://nodejs.org/dist/latest-v6.x/docs/api/http.html#http_server_listen_port_hostname_backlog_callback
Somewhere in your code you should have something similar to this:
var app = express();
app.listen(1234);
Change it to:
var app = express();
app.listen(1234, '127.0.0.1');

Related

Reach Nodejs express app with external ip

So I create a NodeJs express app which I can reach by using my local ip-address (192.168.x.x), but when I use my ISP provided Ipv4 address I got "connection timed out".
The things that I done to make it live:
I disable firewall on ubuntu 16.04.
Open port at my router.
Even I put my local ip-address in DMZ.
If you have any suggestion please let me know!
My very simple code is here:
const app = require('express')();
app.get('/health-check', (req, res) => res.sendStatus(200));
app.listen(25565, "0.0.0.0");

Node - Express -App does not respond to other servers

On Virtual Machine 1 I have a very simple node script
// server.js
var express = require('express');
var annotations = require('./routes/annotations');
var cors = require('cors');
var app = express();
app.use(cors());
app.options('/annotations/:id', cors());
app.get('/annotations/:id', annotations.findById);
app.listen(80, function() {
console.log('Server running');
});
When I access with the browser or curl from my local machine http://example.com/annotations/5770dffb2dc30a7433c729f7 I get instantly the correct data.
But when I try to it from Virtual Machine 2 with a PHP script (file_get_contents or curl), with CURL or even with w3m I cannot access it. PHP and CURL are trying it for long time and then run finally into timeouts, w3m says
Can't load http://example.com/annotations/5770dffb2dc30a7433c729f7.
I am loosing my mind! Any suggestions?
I suppose the issue is the network, not node. Please check if you can
ping 10.55.55.111
from your 2nd VM, assuming that your first VM's IP address running node is 10.55.55.111. If that fails, you have a network problem.
Two possible solutions:
Your two VMs are on different subnets. A great article about VM network adapters can be found at https://www.vmware.com/support/ws4/doc/network_configure_ws.html.
Maybe your first virtual machine has a "Host-only" network? You might need to set the virtual adapter to "Bridged" instead. Further explanation of "Host-only" and "Bridged" network adapters is given at http://slopjong.de/2013/05/14/virtualbox-make-your-virtual-machine-accessible-from-your-host-system-but-not-from-the-local-network/.

Running peerjs-server on OpenShift returns 503 Service Unavailable

I have set up up a node.js 0.10 gear in OpenShift which I deployed a simple server which is based off peerjs-server. All I want this server to do is act as a signalling server to communicate the connection info between peers connected to my application and from then on they communicate peer-to-peer using WebRTC. Everything works when pointing to the demo "PeerJS Cloud" signalling server but when trying to use my own server set up I keep getting returned 503 status codes.
Here is the server creation code I use:
var host = process.env.OPENSHIFT_NODEJS_IP;
var port = process.env.OPENSHIFT_NODEJS_PORT || 8080;
var server = new PeerServer({ port: port, host: host});
NB: I have added host to peerjs-server so I can use OpenShift's IP, not sure if this was necessary but it wasn't working without this either.
The server peerjs-server uses is restify. Here is the server create and listen code:
this._app = restify.createServer(this._options.ssl);
/* A lot of set up code that I have not changed from peerjs-server */
this._app.listen(this._options.port, this._options.host);
Where this._options.port and this._options.host are the ones defined in the previous code segment and I am not using SSL so nothing is being passed in there.
When deploying this code to OpenShift I get no errors but when accessing the site on port 80 or 8000 (the open external ports) I get 503's. I also checked rhc tail and this is what I get:
Screenshot (Can't post images because I have no reputation..). Not sure exactly what that means if anything.
Any help is much appreciated, and if more info is needed I can add more, was not sure what was important information or not.
UPDATE: It's a scaled application using 1-3 small gears.
from https://github.com/peers/peerjs-server/blob/master/lib/server.js:
// Listen on user-specified port and IP address.
if (this._options.ip) {
this._app.listen(this._options.port, this._options.ip);
} else {
this._app.listen(this._options.port);
}
So, use 'ip' and not 'host'. Worked for me.

Why won't simple node.js app doesn't respond on Windows Azure VM?

I am new to node.js, so hopefully I'm missing something obvious.
I have a Windows Azure VM running Windows Server 2012. It has IIS installed and simple, static sites returning static HTML works fine.
I have installed node.js on this server (via Chocolatey). I've created a simple Hello World node.js application (test.js):
var express = require('express');
var app = express();
app.get('/', function(req, res){
res.send('Hello World');
});
app.listen(80);
I fire this up on the server via: node test.js
It works fine on the server when I browse via http://localhost/test.js
It is unreachable from my client machine's browser via http://<servername>/test.js
I have:
created an endpoint on my VM to allow port 80 via TCP;
created a firewall rule on my VM to allow port 80 traffic
a web site on IIS for port 80 and it's running
When I change the above code to listen on a different port (e.g. 2368) and make the appropriate endpoint and firewall rules, everything works great both on the client and the server. I have no problem accessing the site.
What am I missing with port 80 here? Why can't I access my test file via port 80, but I can access it via a different port?
Hopefully it's something obvious. Thank you in advance.

How to deploy a socket.io node.js application on windows azure?

I am building windows azure application which is primarily based on .NET, but I also have to build a socket.io server using node.js hence i need to deploy a socket.io server and use this socket.io url to connect in my .NET application.
I followed all the steps listed here . And I am able to get the socket.io running on my local but when i deploy to cloud, it doesnt start. Please find below a code snippet for socket.io
var app = require('express')()
, server = require('http').createServer(app)
, io = require('socket.io').listen(server, { origins: '*:*' });
server.listen(4001);
When i hosted it in my local emulator, 127.0.0.1:81 was pointing to this in my browser
But 127.0.0.1:4001 showed "Cannot GET /" on the browser, which is an indicative that the socket.io server is running on that url.
But when i deploy the same to cloud, i get the same as the screenshot on the url where the cloud service is hosted but on port 4001 where the socket.io server should have started it says page cannot be displayed.
Please let me know if you need to see any other files like web.config etc.
I have been stuck on this issue from forever and its really crucial for my project, any suggestions or ideas would be deeply appreciated.
Thanks
The important part that you are missing from the sample is setting of the port number
var port = process.env.port || 1337;
and
.listen(port)
when you are running inside of the Azure environment (even emulated) the ports are assigned for you, the port environment variable will tell you where. 4001 is likely not the assigned port.
The 1337 would only be used if you are running by executing
node server.js
from the command line

Resources