NodeJs Application on Aws Ubuntu is running on ipv

2019-09-10 02:10发布

问题:

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.

回答1:

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');