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 Express Basics (2015) Getting Started with Express Improving your first app, some final touches

Vincent Wang
Vincent Wang
1,976 Points

var app = express();

What does this line do in particular?

I am confused because I thought we have already required the express package, so why can't we call express.listen(3000) instead of having to call another method express() for this - what does this method do specifically?

1 Answer

Aaron Price
Aaron Price
5,974 Points
express() 

is a function that returns an object. if you did express.listen(3000) it wouldn't work because the function itself doesn't have a .listen method.

But even if you tried to do this

express().set(/* ... */)
express().use(/* ... */)
express().listen(3000)

it wouldn't work because you would be creating three separate objects, which each would only be self-aware and couldn't use the middleware or values you passed to the other 2.