Categories
JavaScript Answers

How to fix not being able to get CSS file with Node Express?

Spread the love

To fix not being able to get CSS file with Node Express, we expose the folder with the CSS file as a static folder.

Then we write

app.use(express.static(path.join(__dirname, "public")));

to call express.static with the path to expose as the static folder.

Therefore, when we put our CSS file in the public folder, we can get it by using the file name as the URL.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published.