A lightsail implementation with Node.JS - Port 8080 is already in use. As far as I can tell I have set port to 3000.

0

I started the NodeJS and Express implementation using the documentation provided by Bitnami.

I am getting a message port 8080 is already in use when I try and start NodeJS.

bitnami@ip-xx.xx.xx.xx:/stack/projects/sample$ DEBUG=sample:* ./bin/www Port 8080 is already in use bitnami@ip-xx.xx.xx.xx:/stack/projects/sample$ npm start

sample@0.0.0 start node ./bin/www

Port 8080 is already in use bitnami@ip-xx.xx.xx.xx:~/stack/projects/sample$

Chris
asked 2 months ago185 views
2 Answers
0

So this morning I restarted the lightsail instance. Following the instructions set by Ibrahim I first checked running applications. None appeared to be running.

Moving to my sample directory (all of this was already installed by the instance startup). I re-ran the startup instructions.

bitnami@ip-xx:$ netstat -ant | grep 8080 bitnami@ip-xx:$ netstat -ant | grep 3000 bitnami@ip-xx:$ dir bitnami_application_password bitnami_credentials htdocs stack bitnami@ip-xx:$ cd stack bitnami@ip-xx:/stack$ dir apache apps bncert-tool bndiagnostic-regex.ini common gonit licenses nami php projects scripts var apache2 bncert bndiagnostic bndiagnostic-tool ctlscript.sh letsencrypt mariadb peclapcu phpmyadmin properties.ini stats varnish bitnami@ip-xx:/stack$ cd projects bitnami@ip-xx:/stack/projects$ dir node_modules package-lock.json sample bitnami@ip-xx:/stack/projects$ cd sample bitnami@ip-xx:/stack/projects/sample$ dir app.js bin node_modules package.json package-lock.json public routes views bitnami@ip-xx:/stack/projects/sample$ npm install

up to date, audited 136 packages in 1s

17 packages are looking for funding run npm fund for details

found 0 vulnerabilities bitnami@ip-xx:~/stack/projects/sample$ DEBUG=sample:* ./bin/www sample:server Listening on port 8080 +0ms

GET / 200 268.998 ms - 170 GET /stylesheets/style.css 200 3.987 ms - 111 GET /favicon.ico 404 12.913 ms - 1102 GET / 200 10.040 ms - 170 GET /stylesheets/style.css 200 0.783 ms - 111 GET /darkArx/about.css 404 9.282 ms - 1102 GET /Assets/Video/world.mp4 404 15.334 ms - 1102

As you can see the express is running on 8080.

However, my file in ./bin/www has this in it?

var port = normalizePort(process.env.PORT || '3000'); app.set('port', port);

which would I assume try and set the port to 3000? Why then is it running on 8080?

Many thanks in advance of your answers.

Chris

Chris
answered 2 months ago
  • To diagnose further, you can:

    1. Check Environment Variables: Run echo $PORT in your terminal to see if the PORT environment variable is set.
    2. Search for Overrides: Look through your application code for any lines that might be setting the port after the initial configuration in ./bin/www.
    3. Review Startup Scripts: Check any scripts or service definitions that start your application to see if the port is being set there.
    4. Inspect Proxy/Load Balancer Config: If applicable, review the configuration of any proxies or load balancers in front of your application.
  • The AWS documentation for their implementation of Bitnami in Lightsail is simply appalling. It's obvious that some work has been done on implementation and the images used to create the lightsail component. But the documentation is woefully out of date and leading to lots of time being wasted in clearing up confusion. AWS needs to do better.

0

Based on the error message, it seems another process is already bound to port 8080 on your server, preventing your Node.js application from starting on that port. A few things you could try:

  1. Check if another Node.js process is already running on port 8080 using netstat -ant | grep 8080. If so, you'll need to stop that process first before starting your app.
  2. Configure your app to listen on a different port. Edit the bin/www file and change the port, e.g. app.listen(8081).
  3. If using Docker, make sure no other containers are bound to 8080 using docker ps. You may need to specify a unique port when running the container.
  4. Check for any processes listening on 8080 using your process manager (PM2, forever etc). Restarting these may free up the port.
  5. As a test, try stopping all processes with lsof -i :8080 and then restarting your app.

Let me know if checking for other processes on 8080 or changing the app port works! Configuring unique ports is generally good practice to avoid port conflicts when deploying Node apps.

profile pictureAWS
answered 2 months ago
profile picture
EXPERT
reviewed 2 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions