The following error is common for people trying to run a Node.js server on port 80.
Error: listen EACCES 0.0.0.0:80
I used to solve this on my Amazon EC2 server simply by using
sudo node app.js
Now I've learned not to use that method for security concerns. A good solution as explained in this answer is to use:
sudo apt-get install libcap2-bin
sudo setcap cap_net_bind_service=+ep `readlink -f \`which node\``
However I'm not sure how to implement either solution on an AWS Elastic Beanstalk instance, where I don't seem to have SSH access the way I did for the AWS EC2 server, and the only way I seem to have for running anything is in my package.json
file like this:
{
"scripts": {
"start": "node init"
}
}
So I have no idea how I would run other types of commands. How is this done?
By default, Elastic Beanstalk configures the proxy to forward requests to your application on port 5000. You can override the default port by setting the PORT environment property to the port that your main application listens on.
By default, Elastic Beanstalk installs dependencies in production mode ( npm install --production ).
Elastic Beanstalk is one layer of abstraction away from the EC2 layer. Elastic Beanstalk will setup an "environment" for you that can contain a number of EC2 instances, an optional database, as well as a few other AWS components such as a Elastic Load Balancer, Auto-Scaling Group, Security Group.
Beanstalk has a proxy build into it listening on port 80. Your Node.js app should only listen on process.env.PORT
. Once it's done that, you'll be good to go.
Elastic beanstalk will route requests to your instances (at port 80 by default) from its load balancer. So in case you want to expose a particular port, you can add an entry to the load balancer listeners with the load balancer port as your desired port and instance port as 80.
Hope this helps. Can elaborate further if needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With