Steps to Use Subdomains on localhost Manually
1. Edit the hosts file Tell your computer that certain domain names point to your own machine. Open your hosts file: Windows: C:\Windows\System32\drivers\etc\hosts macOS/Linux: /etc/hosts Add this at the bottom: 127.0.0.1 myapp.localhost 127.0.0.1 api.myapp.localhost 127.0.0.1 admin.myapp.localhost Save the file. (You might need admin rights.) 2. Start Your Local Server Make sure your local server (Node.js, PHP, etc.) is running and listening on localhost. If you're using Express, you can detect subdomains like this: app.use((req, res, next) => { console.log(req.subdomains); // ['api'] from api.myapp.localhost next(); }); 3. Open in Browser Now you can visit: http://myapp.localhost http://api.myapp.localhost http://admin.myapp.localhost Each one still points to your local machine. Thanks

1. Edit the hosts file
Tell your computer that certain domain names point to your own machine.
Open your hosts file:
- Windows: C:\Windows\System32\drivers\etc\hosts
- macOS/Linux: /etc/hosts
Add this at the bottom:
127.0.0.1 myapp.localhost
127.0.0.1 api.myapp.localhost
127.0.0.1 admin.myapp.localhost
Save the file. (You might need admin rights.)
2. Start Your Local Server
Make sure your local server (Node.js, PHP, etc.) is running and listening on localhost.
If you're using Express, you can detect subdomains like this:
app.use((req, res, next) => {
console.log(req.subdomains); // ['api'] from api.myapp.localhost
next();
});
3. Open in Browser
Now you can visit:
Each one still points to your local machine.
Thanks