Report this

What is the reason for this report?

How to connect to my node.js application

Posted on February 18, 2020

I span up a Node.js Droplet, cloned my git repo, and did an npm install then an npm start. I got the message:

  • Server is running at http://[::1]:3000
  • Try http://[::1]:3000/ping

If I ping the droplet IP address (ping <dropletIPAddress>) from the terminal, I get a response, but if I try to go to the <dropletIpAddress>:3000, I get “This site can’t be reached”.

What could be wrong?



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!

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.

Hi there,

What I would personally suggest is using Nginx as a reverse proxy so that you could also issue an SSL certificate, you can follow the steps on how to do that here:

https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-20-04

Here is also a YouTube video on how to do the same:

Regarding your specific issue itself, this issue might be due to a few reasons. Here are some steps you can take to resolve the issue:

  1. Listen on the correct IP address: In some cases, applications listen on localhost (127.0.0.1 or [::1]) by default and do not accept connections from other IP addresses. To solve this, in your application, when starting the server, instead of .listen(3000), use .listen(3000, '0.0.0.0'). This tells your application to listen on all available network interfaces.

  2. Firewall: Your firewall may be blocking incoming connections to port 3000. If you’re on a Linux server, you can use iptables or ufw to allow incoming connections. With ufw, the command would be sudo ufw allow 3000. If you’re using DigitalOcean’s firewall service, you’ll need to add a rule to allow incoming traffic on port 3000.

  3. Ensure your application is running: Make sure that your application is still running. Node.js applications will stop if there’s an uncaught exception, or if they are manually stopped. You can use tools like pm2, forever or nodemon to make sure your application restarts if it crashes.

  4. Check server logs: If none of the above works, you should check the logs for your application and your server. They may provide more information on why connections are failing.

  5. Check if the Node.js application is successfully starting: If there’s a problem with the application code, the Node.js process may be crashing on startup. Use npm start and check the console for any error messages.

Remember to replace 3000 with the actual port your Node.js application is running on if it’s different.

Best,

Bobby

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.