Question

How to connect to my node.js application

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?


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.

Bobby Iliev
Site Moderator
Site Moderator badge
July 24, 2023

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

Try DigitalOcean for free

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

Sign up

card icon
Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Sign up
card icon
Hollie's Hub for Good

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

Learn more
card icon
Become a contributor

You get paid; we donate to tech nonprofits.

Learn more
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
Get started for free

Enter your email to get $200 in credit for your first 60 days with DigitalOcean.

New accounts only. By submitting your email you agree to our Privacy Policy.

© 2023 DigitalOcean, LLC.