I tried to load an EJS page using JSDOM however, I can't seem to load the page.
Here's part of my script in app.js:
const { JSDOM } = require("JSDOM");
const dom = new JSDOM('<!DOCTYPE html><p>Hello world</p>');
console.log(dom.window.document.querySelector("p").textContent); // "Hello world"
const list_dom = new JSDOM('views/list.ejs');
console.log(list_dom.window.document);
The first console log is just to make sure that I'm getting JSDOM to work. Here's the result:
Hello world
Document { location: [Getter/Setter] }
I've tried variations of "views/list"
, and "views/list.ejs"
.
Here's my list.ejs:
<%- include('partials/header') -%>
<div class="box" id="heading">
<h1><%=listTitle%></h1>
</div>
<div class="box">
<% newListItems.forEach(function(item){ %>
<form action="/delete" method="post">
<div class="item" contenteditable="true">
<input type="checkbox" name="checkedItem" value="<%=item._id%>" onChange="this.form.submit()">
<p><%=item.name%></p>
</div>
<input type="hidden" name="listName" value="<%=listTitle%>"></input>
</form>
<% }); %>
<form class="item" action="/list" method="post">
<input type="text" name="newItem" placeholder="New Item" pattern="[a-zA-Z][a-zA-Z0-9\s]*" autocomplete="off" required autofocus>
<button type="submit" name="list" value=<%=listTitle%>>+</button>
</form>
</div>
<%- include('partials/footer') -%>