Why am I getting ERR_CONNECTION_TIMED_OUT when trying to reach my server?

April 10, 2019 246 views
Node.js

I am on a node.js one click droplet and after starting my project with node index.js, it appears as though the server is running but when I try to reach it in a browser with the ip address and port, I get ERRCONNECTIONTIMED_OUT. Not sure if theres more I have to configure or if a node js droplet is not the best option? Anything info would help. Below is my index.js of my project..

const express = require('express');
const http = require('http');
const bodyParser = require('body-parser');
const morgan = require('morgan');
const app = express();
const router = require('./router');
const mongoose = require('mongoose');
// const config = require('./config/config');
const cors = require('cors');
const dotenv = require('dotenv');
dotenv.config();

const isLocal = process.env.NODEENV !== 'production' && process.env.NODEENV !== 'development';
const isDev = process.env.NODE_ENV !== 'production';

// App Setup
app.use(morgan('combined')); // logging framework
app.use(cors());
app.use(bodyParser.json({type: '/'})); // parse incoming requests into json no matter type
router(app);

// Server Setup
const port = process.env.PORT || 3001;
const server = http.createServer(app);
server.listen(port);
console.log('\n\n\n\n\n\n\n\n\n\nServer listening on:', port);

2 Answers

Greetings!

The underlying cause could come from many directions, but the bottom line is that you're not able to reach that port on that IP. These are some possible causes for that:

  • Firewall on your computer blocking outbound to that port
  • Firewall on your network/router blocking outbound to that port
  • Firewall on your droplet blocking inbound on that port
  • Our firewall product (if you use it) blocking inbound on that port
  • The application is not listening on the public interface
  • The application is not listening at all

You can check what the application is listening on with a command like this, to see what services are listening on your droplet:

netstat -tulpn

If it's listening on anything other than 0.0.0.0 or the public IP, then it's application configuration. If it is listening on 0.0.0.0 or the public IP, then it's one of the first four options above.

Jarland

Hi. I have the same problem. I have problem with my application configuration?

root@docker-s-1vcpu-2gb-nyc1-01:~# netstat -tulpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 24667/./code-server
tcp 0 0 127.0.0.1:8080 0.0.0.0:* LISTEN 22671/node
tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN 608/systemd-resolve
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1001/sshd
tcp 0 0 127.0.0.1:3000 0.0.0.0:* LISTEN 25880/node
tcp6 0 0 :::6379 :::* LISTEN 21689/docker-proxy
tcp6 0 0 :::22 :::* LISTEN 1001/sshd
udp 0 0 127.0.0.53:53 0.0.0.0:* 608/systemd-resolve

Have another answer? Share your knowledge.