Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialBob Swaney
13,010 PointsHow does the web server function differentiate between the home and user functions?
This may seem like a little bit of a basic question at this point, but in the following snippet,
var http = require('http');
http.createServer(function (request, response) {
router.home(request, response);
router.user(request, response);
}).listen(3000);
How does this function differentiate between the home and user function based on the URL that is entered? is it that when they put in the URL, both router functions are fired, and the URL matches one of the statements in either of the functions? or does it go to the .home method first and seeing that it doesn't match the 'if' condition, it moves on the the .user method instead if there is something after / ...being that they are two different functions themselves?
1 Answer
Dom Ss
4,339 PointsIf you are still on teamtreehouse you could see what is the order of the functions being fired by entering console.logs in every function to see which one is fired first. ;)