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 trialPeter Retvari
Full Stack JavaScript Techdegree Student 8,392 PointsI missed a control step from this: to display to the console whenever a user made a request.
Hi folks, I used this code for myself to make sure that 'somebody' visited 'my page' and made a user request:
console.log("User made a request");
var http = require('http');
http.createServer(function (request, response) {
console.log("User made a request");
response.writeHead(200, {'Content-Type': 'text/plain'});
response.write('Hello World!');
response.end();
}).listen(3000);
console.log("Chill the hell up. Server is running now.");
I used it because it was easier to see it what's happening under the hood / in the background on 'my server' whenever a user visits 'my page' or making a request and last but not least it also helped me to understand more the basic concept of how a server works with Node.js: try it like this. Copy this code to your app.js and save it. After just type node app.js to the console and hit enter. YOU WON'T see the user made request text. You will see it ONLY WHENEVER A USER MAKING A REQUEST. You can now try to visit the port 3000 and observe your console. Now you are able to see "User made a request". So I just wanted to emphasize that it's 2 separated things: 1)server is running => I've made a server 2) user made a request.
Hope it will help somebody.