Unable to start express server on AWS instance

0 votes

I have been searching the whole day the reason of that problem so i've decided to post it:

I can't run my server using PORT=80 npm start

I get the following message :

Port 80 requires elevated privileges
npm ERR! errno 1
npm ERR! server@0.0.0 start: `node ./bin/www`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the server@0.0.0 start script.

npm ERR!     /home/ubuntu/.npm/_logs/2018-03-26T19_52_49_813Z-debug.log

Here is my code : Package.json

  "name": "server",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "prod": "PORT=80 node ./bin/www"
  "dependencies": {
    "body-parser": "~1.18.2",
    "cookie-parser": "~1.4.3",
    "debug": "~3.1.0",
    "express": "~4.16.2",
    "jade": "~1.11.0",
    "mongoose": "^5.0.1",
    "morgan": "~1.9.0",
    "serve-favicon": "~2.4.5"

my app.js

var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var logger = require('morgan');
const mongoose = require('mongoose');

var app = express();

app.use(express.urlencoded({ extended: false }));

mongoose.connect('mongodb://XXXXX:XXXXXX@ds12XXXX.mlab.com:2XXXX/angularXXXX', {}, (err) => {
    if (err) {
    } else {
        console.log('db connection ok!');
    res.sendFile(path.join(__dirname, '../public/index.html'))

module.exports = app;

I'm using : NPM : 5.6.0 NODE : 8.10.0

Already tried : uninstall modules and npm install again, restart AWS instance, checked if port 80 is already used

Thank you for your help

Oct 1, 2018 in AWS by bug_seeker
• 15,310 points

1 answer to this question.

0 votes

It's not your code — you can't connect to port 80 from an app started with non-root account. You could sudo the node app, but that's not a great practice.

There are a lot of ways to fix this, which you can easily find in a search, but the easiest is to just alter the iptables with something like:


Now you can run your node app on 8080, but reach it through port 80. If you run:

sudo iptables -t nat -L

it will show you something like:

target     prot opt source               destination  
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:http redir ports 8080

I think this is a pretty common solution if you're just looking for a quick fix.

answered Oct 1, 2018 by Priyaj
• 56,160 points

Related Questions In AWS

0 votes
1 answer

How to install redis on AWS Micro instance?

Maybe you can spin up an EC2 ...READ MORE

answered Jan 30 in AWS by Archana
• 5,480 points
0 votes
1 answer

Truffle tests not running after truffle init


answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
0 votes
1 answer
0 votes
1 answer
+1 vote
3 answers

Unable to login to parse dashboard on AWS

I had the same issue, which I ...READ MORE

answered Aug 28, 2018 in AWS by eatcodesleeprepeat
• 4,670 points
+1 vote
1 answer

Can we use AWS Public DNS as Domian name to enable https on our instance

I don't believe you can get a ...READ MORE

answered Aug 23, 2018 in AWS by Priyaj
• 56,160 points