How can I handle subdomains request by nodejs?
for example the following code echo test in console for any request on http://localhost:9876/[anything] :
var http = require('http');
http.createServer(function(req, res){
console.log("test");
}).listen(9876);
now I wanna answer any request on http://[anything].localhost:9876/[anything] it can be done by htaccess in apache,what is alternative in NodeJS?
Your application is already capable of handling requests for multiple hosts.
Since you haven't specified a
hostname
:And, you can determine which
host
was used to make the request from theheaders
:Though, you'll also need to configured an IP address for the subdomains in DNS or
hosts
.Or, with a services such as xip.io -- using an IP address rather than
localhost
: