Basic Node and Express (Serve Static Assets)

I didn’t manage to output the css stylesheet using express.static on Repl.
is it something to do with the platform?

app.get(’/’,function(req,res){
res.sendFile(__dirname + ‘/views/index.html’);
});

app.use(express.static(__dirname + ‘public’))

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 11_1_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.96 Safari/537.36.

Challenge: Serve Static Assets

Link to the challenge:

I’m also having the same issue, but I’m not sure why.

I do believe that the app.use() needs to be above the app.get() since Express looks at the routes at the top first, but I have my code ordered that way and it’s still not picking up the style.css

EDIT:
I got my solution to work by clicking the ‘open in new tab’ button in the preview window. That pulled in the CSS and solved the challenge.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.