I gave myself a learning assignment - create a nice website to be hosted from a Node.js server accessible to my home network. My base system is running Windows 7 and I want to give this website a custom domain, so that accessing it from other devices is easy.

I have edited my host file to add mydomain to - now http://mydomain:8080 works on the same machine, but different devices can’t access it (equivalent to localhost, which makes sense that other devices can’t use it). Now I am thinking that I might need a way to make my network ip address static, then map that IP to “mydomain” in the host file.

Is this the best way to make a custom domain accessible, or is there a solution using JavaScript via Node.js/Express (framework)/HTTP where I can keep my IP address dymanic? I have read about using proxies, but might that yield unexpected behavior from my server?

Ideally I would prefer not to have to type the port either and just use something like http://mydomain

Node.js has os.networkinterfaces() available to it - which you are able to iterate through and return the network IP. Maybe I just need a way to map the network IP to a custom domain?

migrated from serverfault.com Sep 30 '15 at 21:23

This question came from our site for system and network administrators.

  • Well I would make sure 8080 is open on the computer the server is located on then edit the hosts file for each of the devices on your network you want to be able to access (You can do this on iOS, Android, OSX, etc). Removing the port is a bit more complicated, but the easiest way would be for you to setup node.js to listen on 80. – Insane Sep 30 '15 at 21:39
  • What’s your main/base OS? If you are on Linux I have some ideas, but want to make sure the solution would fit your needs. – JakeGould Oct 1 '15 at 3:41
  • Well, my idea would be to use a multicast/zeroconfig setup like Avahi daemon which broadcast’s your local machine name to the larger network. Perhaps Windows 7 already has something like that in place and your router is just blocking multicast traffic? But on Linux systems you can generally just install Avahi and with no configuration, your machine’s name would be accessible across the network. – JakeGould Oct 1 '15 at 3:44

So I see a few solutions to your problem:

  1. Some SOHO routers do provide DNS capability in which you could set your ip to static for your machine and create a DNS record.
  2. Most modern OS’s do provide .local address which would be the machinename.local within the private network. You could then run Node.js and use the .local address to resolve to the hosting machine

As for running Node.js on port 80, you should change your .listen function to .listen(80).

var http = require('http');

http.createServer(function (req, res) {
 res.writeHead(200, {'Content-Type': 'text/plain'});
 res.end('Hello World\n');
}).listen(80, "");

console.log('Server running at');
  • 1
    The http protocol use port 80 as the default port. When you type 'mydomain' it will assume the server is on port 80. If the web server not running on port 80, you will have to specify the port. – Luke Farnell Sep 30 '15 at 23:49
  • What about if i go with option 2 - I'm running Windows 7 and I assume that is supported without me needing to set it up. Am I stuck with my website being http://<machinename>.local/ – Chicowitz Oct 1 '15 at 0:11
  • AFAIK unless you setup a DNS server, then your either need to provide the IP address or the .local address so yes, you would be stuck with that domain name. If this is the correct answer, please mark it as correct. – Luke Farnell Oct 1 '15 at 0:19
  • Should be as follows: app.listen(80,, function(){ console.log("======================"); the <computername>.local is only to be used in the browser, not a parameter for the listen fucntion – Luke Farnell Oct 1 '15 at 1:48
  • Do I need to make my computer part of a "Domain" first? Right now it is set to a workgroup. Or maybe I need to add something to the host file? still not working – Chicowitz Oct 1 '15 at 2:02

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.