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 User Authentication With Express and Mongo What is Authentication? Review: Node, Express and npm

Rashadat Mirzayev
Rashadat Mirzayev
14,601 Points

app.use(express.static( __dirname + '/public')); The same syntax as in video,but this is wrong answer for this question

Complete the code below so that Express serves static files (like CSS and images) from the public folder located in our applications root folder:

// serve static files from /public app.use(express.static(...dirname + '...'));

Can't find the right solution. Anyone passed this test?

4 Answers

Daan Schouten
Daan Schouten
14,454 Points

From the top of my head, /public doesn't look very good.

Either use the ' ./ ', if the folder is in the same directory as the file you're running, or use the '../', if the folder is one directory above the file you're running.

I'm guessing it's the first in your case. Thus:

var path = require('path');
 app.use(express.static(path.join(__dirname, './public')));

Notice the path.join, which does the same as the your '+' but in a different manner.

Rashadat Mirzayev
Rashadat Mirzayev
14,601 Points

Thks, Daan Schouten, but I tried both of this syntax, and neither works..

Daan Schouten
Daan Schouten
14,454 Points

This might be due to the fact that you can't access the path package. What about keeping your code the way it is, but changing /public to ./public ?

Rashadat Mirzayev
Rashadat Mirzayev
14,601 Points

I tried all version, with one dot, two dots, without dot, without slash... can't pass this question.

I'm having the same issue

Same issue. Does not want to accept it any way.