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 trial

JavaScript Introducing the Project

I don't understand the code in the www.js file

There is a lot of boilerplate code already written for this course that doesn't make sense to me (and its frustrating that there's no explanation of it).

In the www.js file the http module is required and a server is set up.

var http = require('http');
 * Get port from environment and store in Express.

var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);

 * Create HTTP server.

var server = http.createServer(app);

 * Listen on provided port, on all network interfaces.


Why is any of this necessary? With Express you can just use app.listen(port). I don't see why all the above code is necessary.

There is some other stuff that seems unnecessary as well. Like this function:

 * Normalize a port into a number, string, or false.

function normalizePort(val) {
  var port = parseInt(val, 10);

  if (isNaN(port)) {
    // named pipe
    return val;

  if (port >= 0) {
    // port number
    return port;

  return false;

Why would you need to "normalize" the port number? For what purpose? It's a bit frustrating how this stuff is just written for you with no explanation.

1 Answer

Guil Hernandez
Guil Hernandez
Treehouse Teacher

Hi there. As mentioned at the beginning of the workshop, I used the Express application generator to spin up the Express app. :)

Right, thanks. I do like your course, and actually all your courses. Just getting to the end of the FullStack JS track and finding myself getting frustrated and a bit overloaded. Probably just need to sleep on a lot of this. Thanks again Guil.