11

Can somebody explain how to run my reactJS app on port 80, without specifying port

currently it works on www.mydomain.com:3001 but I want it to be visible when I go to www.mydomain.com

I can't find the solution on create-react-app docs website so I'm asking here.

If I run application with

sudo npm start

I get error that something is already using port 80 (I did specify PORT= 80)

Thanks

1
  • 2
    By default npm does not have root privilege. That means, If you try to run any application which uses port below than 1024 port, you need a sudo access. If that is the case, you can run your create-react-app with sudo PORT=80 npm start. That should do the job. Hope this helps Commented Feb 13, 2018 at 8:59

1 Answer 1

10

you have to specify PORT env variable to run on port 80 PORT=80 npm run start

Sign up to request clarification or add additional context in comments.

5 Comments

This doesn't work on Windows environments.
On windows, set PORT=80 should do the same thing
using sudo PORT=80 npm run start
you can use npm run build command to build a production-ready app. You can host the folder created inside build directory to nginx or any other server which can run it on port 80.
It's a really bad idea to run npm with sudo privilege. Better to run a local tunnel from react server's port to port 80, that way only the tunnel needs sudo.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.