Tell us what’s happening:
Hi everybody, I’m stuck and I can’t understand why.
I am trying to use the “express.static()” method as the middleware to serve static assets from the “public” folder, as explained in the help section. But I get the " Your app should serve asset files from the /public directory" and can’t pass the challenge.
Could someone please help.
Your code so far
app.use("/assets", express.static(__dirname + “/public”));
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36.
Could you share your repl.it code ? The test requires you to serve a file called style.css which you may not have or the code may be failing to serve it.
If you pass the first parameter to app.use, you’re telling express to do whatever the second parameter does to that path (the express.static in this case).
In this case, you are telling it to serve everyting under public as /assets, hence the HTML files should have paths pointing to the /assets route instead, like this:
For others having trouble with errors: you may need to just click the Stop and Start 4-5 times and keep resubmitting your code. In other words, you can have the right answer and it still throws errors insisting the path is “/public” even though you have that. Eventually it catches on and passes.