Using ejs with Node.js and Express

Hello , in this article i’ll show you how to add js code into html using ejs with Node.js express framework.

See express doc for more.

Ejs is an html template.Html into easy js code.You can simply embed js code in html.Just as we can write php code in html. Since it is a module, you need to install it. You can install npm install ejs in the folder where your project is located.

When encoding on Express, pages with the extension .ejs are generally kept in the Views folder. In the example I have written, I have carried out such transactions.

We need to create our files as index.ejs, not index.html. There are many templets on the market, but express normally uses jade templete, but in my opinion, ejs is a more successful and legible templete.

See the example I wrote below.

  • app.js
  • index.ejs

The use is quite simple as you can see. You can call other pages on the page <% – include (‘header order) -%> and write your site modularly. If you wish, you can change the opening and closing signs according to yourself.

See ejs doc for more.

You may also like...

Leave a Reply

Your email address will not be published.