How to access macOS localhost (port 3000) from Parallels IE?

The "technical background" of the special behavior (at least on Macs) of using localhost as "host constant" is the specific nature of dns.js, which obviously binds the node http/https server to the interface it reverse-resolves to the const host (= localhost) with the help of mDNSResponder.

This is localhost > 127.0.0.1 > lo0.

Any other interface like en0/en1 as physical interfaces or vnic0/vnic1 as Parallels' virtual interfaces won't be addressed/attached.

To solve this you may either

  • set up a DNS-server like dnsmasq in Parallels' Host-only network and use the fqdn of the node http server host as host const
  • use the IP-address of the node http server in Parallels' Host-only network as host const
  • modify the hosts files of every host in Parallels' Host-only network and add a line like 10.37.129.2 testserver.example.com and use testserver.example.com as host const

One of the way I could use it, I found my local IP4 address provided by the router.

From Mac system preferences > Network > IP Address: 192.168.x.xx

And let say if you access it in Mac with http://localhost:3000 you can do it also with http://192.168.x.xx:3000 from Mac itself and from Parallel Windows OS with shared network configuration.

This IP address could be changed each time you restart the router or choose another router etc.

Currently, I'm using Parallels Desktop 12


The temporary solution is to edit server.js and set host = '10.37.129.2' or set the HOST system variable to 10.37.129.2 and read it in with host = process.env.HOST || 'localhost'. It may also be possible to edit /private/etc/hosts to map 10.37.129.2 to localhost, though my quick test of that failed.

Everything was behaving precisely as expected. The localhost name is mapped to 127.0.0.1, and not to any network facing IP address. Thus 10.37.129.2, which was my Mac's IP on the virtual network shared with Windows running in Parallels, was never reaching localhost. This is correct and reasonable.

All credit goes to klanomath. Thanks!