5

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 127.0.0.1 - 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?

1
  • 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, 2015 at 21:39

1 Answer 1

2

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, "127.0.0.1");

console.log('Server running at http://127.0.0.1:80/');
5
  • 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. Sep 30, 2015 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, 2015 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. Oct 1, 2015 at 0:19
  • Should be as follows: app.listen(80, 127.0.0.1, function(){ console.log("======================"); the <computername>.local is only to be used in the browser, not a parameter for the listen fucntion Oct 1, 2015 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, 2015 at 2:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .