How can I develop locally using a domain name instead of 'localhost:3000' in the url with create-react-app? How can I develop locally using a domain name instead of 'localhost:3000' in the url with create-react-app? reactjs reactjs

How can I develop locally using a domain name instead of 'localhost:3000' in the url with create-react-app?


As well as changing your /etc/hosts as advised above, if you want CRA to know about the new host name, the HOST env var should give you what you want.

E.g. (this can go into your package.json under scripts/start)

HOST=somedomain.com react-scripts start

That should start your CRA-based dev server, listening at that domain name, and it should open/refresh a browser tab pointing there.

Edit: docs on this and other env vars that CRA uses.


Combining some of the other answers:

Step 1: on your local machine add this line to your etc/hosts file:

127.0.0.1 somedomain.com

Step 2: in your react app directory .env file, add:

HTTPS=true

HOST='somedomain.com'

Step 3: (Depending on whether you're running a backend) you may need to add somedomain.com as an allowed domain


You can do it by updating your hosts file with the following entry

127.0.0.1 somedomain.com

and then use somedomain.com to access your site

But if somedomain.com happens to be your actual host address then you will have to revert it back when you want to connect to the actual hosted somedomain.com

You can find more info about how to edit your host file here: https://www.siteground.com/kb/how_to_use_the_hosts_file/

There a similar answer which you can find here: Assigning a domain name to localhost for development environment