Categories
JavaScript Answers

How to include CSS files using Node, Express, and ejs?

Spread the love

To include CSS files using Node, Express, and ejs, we serve them as static files.

For instance, we write

app.use(express.static(__dirname + "/public"));

to serve the /public folder as a static files folder with express.static.

Then we add the css file in our ejs template with

<link rel="stylesheet" type="text/css" href="css/style.css" />

By John Au-Yeung

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

Leave a Reply

Your email address will not be published. Required fields are marked *