So I have my app at http://localhost:8080/
How can I have http://localhost:8080/subpage
? Because it seems like any page that hits :8080 pulls
Here is a start:
var http=require('http');
var url=require('url');
var server=http.createServer(function(req,res){
var pathname=url.parse(req.url).pathname;
switch(pathname){
case '/subpage':
res.end('subpage');
break;
default:
res.end('default');
break;
}
}).listen(8080);
I hit the same problem as you did, and I think what we were both looking for is basically a routing engine for node.js. Basically, okay fine I get the hello-world example for nodejs, but how do I build something that responds to different requests?
For future users who land on this page via google, you must look at Express.js and this excellent guide and intro into express, Understanding Express.js. These two will solve the problem