Search code examples
node.jsurlnetwork-programmingdnswifi

Is there a way to "give a url" to a website runned in a WLAN?


I've developed a small application to manage grocery using Node.js and Express, and I run it locally on my pc. There are other three computers in my home: all four computers are connected to my wi-fi and need to access to my grocery application.

In this scenario, my computer acts as a "server": the other three connect to mine using my IP and the port I've set in Node.js (eg: to access in my application I type in my browser "http://localhost:3000/", while from the other three computers it's something like "http://192.168.x.x:3000/").

My problem is the following: since I'm connected to wifi, I found that my IP address often changes, so everytime this happens I have to look for my address (using ipconfig) and manually update the bookmarks saved in the other computers. I was wondering if there is a program / method / script / something that I could do to give my computer some sort of "local url" or something similar to a "local DNS", a name that can be used to find my pc in the WLAN. I've already tried to set my wi-fi router in order to have static IPs but for some reason that doesn't work well with my internet connection, so I was hoping for a different solution.

Thanks for your help!


Solution

  • While some smart routers have DNS capabilities, my experience is that most home routers do not. This solution can work without built in DNS capabilities for your router, and while it is not exactly 'DNS' it should keep you from having to reset the bookmarks on the other computers. Depending on your router, you should be able to adjust the DHCP range of IP addresses that it can assign to devices. You can set it to a smaller range of addresses, and assign your host computer a static address, so it doesn't change.

    For example, lets say your network is using 192.168.0.x/24 addresses. So the router by default will most likely assign IP addresses in a range from 192.168.0.2 (the router is usually 192.168.0.1) to 192.168.0.254. You could adjust the DHCP range in your router settings to assign an IP address range from 192.168.0.1 to 192.168.0.250, and then manually set your host computer's address to 192.168.0.251. On all the other computers, you can now set the bookmarks to 192.168.0.251, and you shouldn't have to change them. You could also edit the hosts file (on Windows machines) so it maps an internal domain name, such as groceries.com, to your host machine, 192.168.0.250. To change the hosts file, go to C:\Windows\System32\drivers\etc, then open the hosts file in notepad, and enter in the desired domain name and IP address. Once the hosts file has been edited on all the client computers, you can just use groceries.com as the url from any browser on the computer

    here's a link for manually setting the IP address on a Windows 10 PC https://support.microsoft.com/en-us/help/15089/windows-change-tcp-ip-settings