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

Why not just name the express variable app?

The current code is as follows:

var express = require('express'); // Require express module and assign it to express

var app = express(); // Assign express to app variable

At first glance, this seems like a rather round about way to get the express method assigned to the app variable. My first instinct is to simply write:

var app = require('express'); // Require express module and assign it to app variable

So is there a reason to do it the way it was presented in the video as oppose to the way I just wrote it? Is this simply for the sake of readability or is there an issue of syntax that forces the first method to be convention?

1 Answer

But there's a set of parentheses after express() in the second line:

var express = require('express'); 

var app = express();

So this isn't a case of:

var a = b;
var app = a;

So then wouldn't the solution be to just write:

var app = require('express')();

or is there a reason to keep the express variable for some other use?