Set View Engine:
app.set(`view engine`, `ejs`)
Render HTML File: Replace
response.sendFile
with
response.render
:
response.render(`index`) // if your HTML file is called index.ejs
Render Data: Render HTML with data:
let data = {
yourKey: yourValue
}
response.render(`index`, data)
Embed Data: In your HTML, embed the data:
<%= yourKey %>
Embed JavaScript: In your HTML, embed JavaScript:
<% if (someCondition) { %>
some HTML
<% } %>
Include HTML: In your HTML, include another HTML file:
<%- include(`another-file.ejs`) %>