How to add css file to ejs Express js 1

In this tutorial, we will learn to include/add CSS style file link in your EJS file.


Step 1:

Create a public folder at the root of your project.  Create a css folder inside it.


The project directory should look like the below:














Step 2:

Add the following line to the index.js file which is at the root of the project folder:




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



Step 3:

Assuming you put the css files in public folder from in your app root. now you have to refer to the css files in your EJS view template files, like:



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



Hope it hepled!