# npm
$ npm install @macchiatojs/views
# yarn
$ yarn add @macchiatojs/views
First, you should create a directory in which you have all views templates. You can do it by run this command and make sure your in the source code folder;
mkdir views
Second, you should create a template file. You can do it by run this command;
touch views/home.html
Third, you should put your ejs logic inside the file. something like;
<ul>
<% users.forEach((user) => {%>
<li><%= user.name %></li>
<% })%>
</ul>
Finally, you can use @macchiatojs/views
;
import ViewEngine from "@macchiatojs/views";
const viewEngine = new ViewEngine({
root: path.join(__dirname, "views"),
viewExt: "html",
});
const htmlString = await viewEngine.generateHtml("home", { users });
// htmlString have a string with this values
// <ul>
// <li>Jawher</li>
// <li>Imed</li>
// <li>Tom</li>
// </ul>