Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript Express Basics (2015) Serving Static Files in Express Setting Up the Express Static Server in Development

Why are we using '/static' - as opposed to '/public'?

Curious as to why we use '/static' vs any other term, especially '/public'?

3 Answers

Andrew Chalkley
Andrew Chalkley
Treehouse Guest Teacher

I haven't seen this particular video but static and public are both common directories for "static assets" or "publicly accessible assets".

Anthony c
Anthony c
20,907 Points

Is there an upside to passing the files through "/static"?

Why not just name the "public" folder "static" to begin with?

why this?

app.use('/static', express.static(__dirname + '/public'))

and not this

app.use(express.static(__dirname + '/static'))
Matthew Day
Matthew Day
6,740 Points

I would love to know the answer to this, as well.

.static is built in middleware for Express.js. So using /static directory to store all your static asset files is -- although extremely helpful -- simply a naming convention.

In the context of the massive info dump that comes with inevitably distilling a complex toolset into a few short videos, this can seem like just one more little thing to remember.