DEV Community

Hidayt Rahman
Hidayt Rahman

Posted on

Serve localhost with custom domain

We are going to use your preferred custom domain in local instead of the dull localhost URL on our local system.


For this example, I am using the domain name, but you can use your own.

Open the hosts file in your machine.

For Window:
To update the hosts file in Windows, you can follow these steps:

  • Press the Windows key
  • Type Notepad in the search field
  • In the search results, right-click Notepad and select Run as - administrator
  • Open the hosts file at C:\Windows\System32\Drivers\etc\hosts
  • Make the necessary changes to the file
  • Select File > Save to save your changes

For Mac:
Open terminal and run the command below

$ sudo nano /private/etc/hosts
Enter fullscreen mode Exit fullscreen mode

And update the hosts file, replace the domain name with your domain.


# Host Database
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
## broadcasthost
::1             localhost
# Added by Docker Desktop
# To allow the same kube context to work on the host and the container: kubernetes.docker.internal
# End of section

# This entry was appended by Docker Desktop because `localhost` did not resolve
# to a list of addresses which included This can happen due to a bug
# in the macOS migration assistant, or possibly because another tool has
# corrupted the file.       localhost
Enter fullscreen mode Exit fullscreen mode

Save the file and restart the machine.

Try to access the localhost app by your domain, in my case it will be

Do not forget to add the port :PORT
Enter fullscreen mode Exit fullscreen mode

It should start running the app with the custom domain.

Happy.Coding :)

Top comments (0)