Connection refused with port 3000

Posted July 2, 2021 113 views

I am following this tutorial for my node application.
Actually I want to use root folder for angular and sub directory ‘api’ for node js API.
So I’m trying to connect port 3000 for node js app.
But I am getting connection refused message. This port in not in listen state.
So I have followed this link.

But still I have the same issue.
My /etc/nginx/sites-available/default is,

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /var/www/html;

    # Add index.php to the list if you are using PHP
    index index.html index.htm index.ts;

    return 301$request_uri;

    location / {    
        try_files $uri $uri/ =404;

    location /api/ {
        proxy_pass http://localhost:3000;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;


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.

Submit an Answer
1 answer

Hi @kenlyle64,

So you’ve configured a reverse proxy using Nginx. That’s the first step!

It seems to me like your Application is not started/listening to the proper port.

What I’ll suggest is to start your NodeJS application on port 3000 and type in the droplet the following

netstat -tlupen

Paste the output of the command here.

Do you see port 3000 there?

  • Hi,

    Thank you for your reply.

    No I didn’t see the port 3000.

    Proto Recv-Q Send-Q Local Address           Foreign Address         State       User       Inode      PID/Program name
    tcp        0      0*               LISTEN      112        960446     502340/mysqld
    tcp        0      0*               LISTEN      112        960451     502340/mysqld
    tcp        0      0    *               LISTEN      0          1257488    532667/nginx: maste
    tcp        0      0 *               LISTEN      101        17402      614/systemd-resolve
    tcp        0      0    *               LISTEN      0          22323      775/sshd: /usr/sbin
    tcp        0      0   *               LISTEN      0          1257490    532667/nginx: maste
    tcp6       0      0 :::80                   :::*                    LISTEN      0          1257489    532667/nginx: maste
    tcp6       0      0 :::22                   :::*                    LISTEN      0          22334      775/sshd: /usr/sbin
    udp        0      0 *                           101        17401      614/systemd-resolve

    So I have referred this link to open port 3000. But after some time port 3000 closed automatically.

    • Hi @kenlyle64,

      The thing is your port can’t be reached because nothing is listening on it. Basically, your NodeJS app is not starting correctly it seems.

      Have you installed PM2 from the tutorial you provided? When you try and start your NodeJS app what does it say?