All ports not available with React npm run start - node.js

So up until yesterday I was able to do npm start no issues.
The versions of things I'm running
OSX Mojave...
npm: '8.19.3',
node: '19.2.0',
Now it is saying that port 3000 is in use. I've done all the tricks to see if 3000 is in use is isn't
changed the port to 3001 3005 4444 and various other and it doesn't work.
Still the same message.
serve -s build works great and runs the app on 3000. no idea what is going on..
error message
✔ Something is already running on port 4001.
Would you like to run the app on another port instead? … no
I've tried
user#computer >> npx kill-port 4001
Could not kill process on port 4001. No process running on port.
user#computer >> mtbcrm_react % lsof -i tcp:4001

Related

Is this dockerfile set correctly to serve a React.js build on port 5000?

I have a React.js app which I have dockerized and it was working fine until yesterday when there was some kind of an error which I found out is due to node version 17 so I decided to get the docker image's node version back to 16. All good, but since I did this, I cannot get the docker image to run on the specified port.
Here is my dockerfile:
ROM node:16.10-alpine as build
RUN mkdir /app
WORKDIR /app
COPY /front-end/dashboard/package.json /app
RUN npm install
COPY ./front-end/dashboard /app
RUN npm run build
# Install `serve` to run the application.
RUN npm install -g serve
# Set the command to start the node server.
CMD serve -s -n build
# Tell Docker about the port we'll run on.
EXPOSE 5000
As you can see, I am making a build which I then serve on port 5000 but for some reason that does not work anymore and it used to work fine.
All I can see as an output in docker is:
Serving! │
│ │
│ - Local: http://localhost:3000 │
│ - On Your Network: http://172.17.0.2:3000
When I go to localhost:3000 nothing happens which is fine but it should be working on port 5000 and it does not run there. Any idea why I cannot run the docker image's build on port 5000 as I used to do before?
I use docker run -p 5000:5000 to run it on port 5000 but this does not solve the problem.
I faced issues at work due to this exact same scenario. After a few hours of looking through our companies deployment pipeline, I discovered the culprit...
The serve package.
They changed the default port from 5000 to 3000.
Source: serve github releases
So, to fix your issue, I recommend to add -l 5000 in your serve cmd.
From the logs you can see that your application might be listening for traffic on localhost:3000. Your EXPOSE 5000 line does not change that behaviour but makes Docker (and other users) think port 5000 is important. Since nothing is listening on port 3000 obviously you should get a 'connection refused'. You may want to lookup https://docs.docker.com/engine/reference/builder/#expose
To get out of that situation:
ensure your dockerized process is listening to 0.0.0.0:5000. You will have to add -l tcp://0.0.0.0:5000to your CMD line (see https://github.com/vercel/serve/blob/main/bin/serve.js#L117)
When running the container, ensure you expose the port by using docker run -p 5000:5000 ...
If need be tell your docker host's firewall to allow traffic to <ip>:5000
Now if you connect to http://<ip>:5000 you should see the application's response.
Your app is listening on port 3000. So you need to map whatever port you want to use on the host to port 3000. If you want to use port 5000, you should use -p 5000:3000. Then you should be able to access it using localhost:5000 on the host machine.
You should think of containers as separate machines from the host. So when the container says that it's listening on localhost:3000, that means localhost in the context of the container. Not the host.

Starting a simple HTTP-server using "npm" without installing npm

Which command do I need to use to start a simple HTTP server using "npm", the specified port to be used is port 8080. Also, I don't have to download the npm package. The only hint I got is that I can download the basic web server packet, also from there I can specify the port 8080?
Once the http server has been configured with the x-server name at port xxxx, you can start it with the command:
x-server -p xxxx
for example if my server's name is simple-http-server at port 8080:
simple-http-server -p 8080
would start it.
for the next exercice:
php -S 127.0.0.1:8080
I am also getting started on HTB.
contact me (in the next 23 hours) at this account or leave a correspondance as comment if you want to work with me to break through on HTB.
Once npm is installed, the command is simply: http-server -p 8080 (without writing 'npm' at the beginning of the line).

Ubuntu: Http-server on port 80 starting up, but can't access from browser?

So I have a web application being run on an http-server via npm. In my package.jsonfile, I have the line "start": "sudo http-server -a [my ip address] -p 8065 -c-1", and my app runs fine when I go to http://myipaddress:8065. However if I change the 8065 to just 80, in the json file (which is what I want), I still get the success message:
Starting up http-server, serving ./
Available on:
http://myipaddress:80
But when I go to the link, chrome givess me an ERR_CONNECTION_REFUSED. Anybody know what's going on?
I would suggest there are three possible problems here.
Port 80 is already in use.
You are not running the application as root (you can't bind to ports <1024 if you are not root)
http-server isn't binding correctly
To check if port 80 is already in use try
netstat -lntu | grep :80
If port 80 is already in use you should see something like
tcp6 0 0 :::80 :::* LISTEN
You will need to close whatever is running on port 80 (apache? nginx?)
To check if you can actually bind to port 80, try running http-server from the console rather than via npm i.e.
sudo http-server -a [my ip address] -p 80 -c-1
If the above works you should be able to run npm as root to start your http-server i.e.
sudo npm start
You may need to remove sudo from your package.json:
"start": "http-server -a [my ip address] -p 8065 -c-1"
We need to make sure that http-server is working correctly on your system. We will test it with w3m a console based web browser.
You may need to install w3m with sudo apt-get install w3m if you do not have it already.
create a new directory. mkdir /tmp/testing
CD into new dir cd /tmp/testing
Start http-server with `http-server . -a localhost -p 1234
Visit http://localhost:1234 with w3m w3m http://localhost:1234/
Start http-server with `http-server . -a localhost -p 80
Visit http://localhost in a w3m w3m http://localhost/ does it work?
Quick tests:
Try to access this on as the localhost address, either localhost or 127.0.0.1 to shortcut any potential firewalls.
Try to telnet to this address on port 80 to see what the server replies (if any).
Do you have Apache installed? Are sure putting your application server on port 80 is not in conflict with Apache?
In that case it is better to redirect port 80 to your application server that just starting it on the Apache port.
Is it error 102? Check this link. Probably it's caused by some extensions you installed.
To run nodejs apps with pot less than 1000 you need a root access. Use sudo node app.js Also dont forget to open firewall. And make sure nobody else listening on port 80.

phonegap changing from port 3000

On the c9 IDE(c9.io) i installed node and phonegap globally, and started to build an app.
I can run the app on port 3000 by usign the command: phonegap serve
but i would like to run in a diferent port, using:
.listen(process.env.PORT, process.env.IP);
that is the way to run node app on c9.io:
https://docs.c9.io/docs/writing-a-nodejs-app
I am having trouble to find the file to edit and change the port.
Thanks
phonegap serve -b $IP -p $PORT
thant is the command to run on c9

Application generating "Error: listen EACCES" while starting application with pm2 on port 80?

We are using pm2 for starting my nodejs app on port 80 on ubuntu. But the application generating error **Error: listen EACCES**. Our pm2 version is 0.12.7 and we are using the following command:
sudo pm2 start app.js -- dev
On running whereis node we get the following result:
node: /usr/bin/node /usr/sbin/node
We have already tried following commands:
sudo apt-get install libcap2-bin
sudo setcap cap_net_bind_service=+ep /usr/local/sbin/node
Any idea where are we going wrong?
Sounds like you might have another service already listening on port 80. try this:
sudo netstat -tulpn
The output of this will tell you if any other process is currently using port 80.

Resources