run npm start with sudo doesn't allow access port 80 - node.js

I have a EC2 running instance from AWS and I tried to run my node server on port 80 using sudo npm start which is just running script node ./bin/www but it crashed and telling me port 80 requires elevated privileges. It was fine if I just do sudo node ./bin/www. I am not sure why and it seems the npm just doesn't accept my sudo.
I tried to run npm start as a root user and it still wouldn't let me to access port 80.

Related

All ports not available with React npm run start

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

How do i overcome EADDRESS already in use in PM2

I am running a node js server on aws EC2 instance
when i do node server.js its working but when i start the server using pm2 i am getting code: 'EADDRINUSE',
after installing pm2 can't even use node server.js it also says EADDRINUSE, so to rerun it i have to uninstall the pm2 and stop the node process that runs port 3000, but as soon as i install pm2 the port 3000 is becoming unavailable
root 47971 0.7 2.7 647924 55712 ? Ssl 11:20 0:00 node /home/ubuntu/kanaswap-name-service/server.js
the above process runs automatically when i install pm2 , i cant even kill that process
when i run node server.js
pm2 list
process that runs on port 3000
even after killing the process it runs automatically,
this happens because everytime you start pm2 it says that a service on that port alredy running try changing the port no or you can kill the process if you are using linux
here is the command for kill the process in linux
this is for getting PID
lsof -i:<port no.>
after that you may find that result
node 14977 USER 22u IPv4 191006 0t0 TCP *:3004 (LISTEN)
after that run this
kill 9 <port no.>

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).

How to access node.js site with direct url without mentioning port 8080 in aws ubuntu, Apache2

My node.js application is running on port 8080. I want to access it via url without mentioning port number in the URL. How will i achieve this?
for example :
current : www.domainname.com:8080
Expected :www.domainname.com
Ubuntu os version: 16
Server : Apache2
Need help.
Use Nginx as a reverse proxy for your node js application and mentioned your port in nginx config file.(you can create new config file or you can use default one /etc/nginx/nginx.conf)
Install pm2 and Use pm2 tool to keep running your nodejs application in the background.
curl -sL https://deb.nodesource.com/setup_10.x | sudo bash -
sudo apt-get install -y nodejs
sudo npm install pm2#latest -g
pm2 start myapp.config.js (replace myapp.config.js with YOURAPP.js )

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