How to use font-awesome in ejs file from node modules?

1.2k views Asked by At

I have installed font-awesome 4.7 in my nodejs application

I have to get it in my views.ejs file.

i tried importing using tag...

<link rel="stylesheet" href="../node_modules/font-awesome/css/font-awesome.min.css" >

and from css file like this...

@import url('../node_modules/font-awesome/css/font-awesome.min.css');

but they doesn't help....

It is failing to load when looking at the browser's network tab...

Please help.. Thanks in advance!

2

There are 2 answers

0
Jordan On BEST ANSWER

I have an ejs app in production that uses font awesome and I just use the CDN. But also Atheesh Thirumalairajan post is a valid way. Just make sure you are serving from a public folder.

<script src="https://kit.fontawesome.com/c03ec31dc2.js" crossorigin="anonymous"></script>
0
Atheesh Thirumalairajan On

You need not use node_modules instead, the easy way of doing it is to download Font Awesome from https://fontawesome.com/v4.7.0/get-started/

Then, extract the files your public folder (You need to define the public directory in express)

Then, In the <head></head> section of your HTML, add:
<link rel="stylesheet" href="path/to/font-awesome/css/font-awesome.min.css">

You can also checkout their official examples. The same thing applies to Font Awesome 5 But, you need to download from https://fontawesome.com/how-to-use/on-the-web/setup/hosting-font-awesome-yourself