Question

Can't reach my Node.js application

Hello world! I’ve created a Ubuntu NodeJS 8.10.0 on 18.04 droplet. I’ve deployed a Node.js app, tested on my computer. I can reach my app from inside the Droplet. curl http://localhost:3000 I can’t reach my app from my computer. curl http://123.456.789.012:3000 This is not the real IP.

Any ideas?

Thank you!!!


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

jarland
DigitalOcean Employee
DigitalOcean Employee badge
April 18, 2019
Accepted Answer

Greetings!

I would bet that your application is listening on 127.0.0.1, as opposed to the public interface. If you run netstat -tulpn you should see the applications listening, and it might look something like this:

[root@gateway] ~ # netstat -tulpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      693/systemd-resolve
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1392/sshd
tcp6       0      0 :::22                   :::*                    LISTEN      1392/sshd
udp        0      0 127.0.0.53:53           0.0.0.0:*                           693/systemd-resolve
udp        0      0 10.128.0.5:68           0.0.0.0:*                           673/systemd-network
udp        0      0 127.0.0.1:323           0.0.0.0:*                           1756/chronyd
udp6       0      0 ::1:323                 :::*                                1756/chronyd

Notice on my system that systemd-resolve is listening on 127.0.0.1, so it is only reachable internally. Meanwhile, sshd is listening on 0.0.0.0 which means all interfaces, making it accessible both internally and externally.

Your application most likely defines this somewhere in it’s configuration, and can be adjusted. If you’re not sure where, maybe a grep through it’s code can help, something like:

grep -R "127.0.0.1" *

Or even:

grep -R "localhost" *

If it isn’t configured anywhere, it’s probably an assumed default and it is required that you specifically define the value to change it.

Jarland

iptables -I INPUT -p tcp --dport 3000 -j ACCEPT

worked for me, thanks in milllions

This comment has been deleted

    Try DigitalOcean for free

    Click below to sign up and get $200 of credit to try our products over 60 days!

    Sign up

    Get our biweekly newsletter

    Sign up for Infrastructure as a Newsletter.

    Hollie's Hub for Good

    Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

    Become a contributor

    Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

    Welcome to the developer cloud

    DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

    Learn more
    DigitalOcean Cloud Control Panel