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 trialRashadat Mirzayev
14,601 Pointsapp.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
14,454 PointsFrom 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.
Daan Schouten
14,454 PointsThis 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
14,601 PointsI tried all version, with one dot, two dots, without dot, without slash... can't pass this question.
Brandon Tindle
13,618 PointsI'm having the same issue
Janet Popplewell
25,352 PointsSame issue. Does not want to accept it any way.
Rashadat Mirzayev
14,601 PointsRashadat Mirzayev
14,601 PointsThks, Daan Schouten, but I tried both of this syntax, and neither works..