EJS Syntax error, not able to render records in browser from MongoDb

Viewed 344

Index.ejs written as below :

<% include ../views/partials/header %>
  <ul>
    <% todos.forEach(function(todo){ %>
      <li><%= todo.text %> - <%= todo.body %></li>
    <% }) %>
  </ul>
<% include ../views/partials/footer %>

I can console.log the the database records, however I get a syntax error the EJS file.

When I run node app.js in the console, I get the below in the console.

MongoDB connected
Server runnng on port: 3000
[ { _id: 5986375b48422cf78471d7d6,
    text: 'My ToDo One',
    body: 'This is my first todo app' },
  { _id: 5986379748422cf78471d7e8,
    text: 'My ToDo Two',
    body: 'This is my second todo' } ]
SyntaxError: missing ) after argument list in /home/rizwan/Documents/projects/todoapp/views/index.ejs while compiling ejs

If the above error is not helpful, you may want to try EJS-Lint:
https://github.com/RyanZim/EJS-Lint
    at new Function (<anonymous>)
    at Template.compile (/home/rizwan/Documents/projects/todoapp/node_modules/ejs/lib/ejs.js:549:12)
    at Object.compile (/home/rizwan/Documents/projects/todoapp/node_modules/ejs/lib/ejs.js:358:16)
    at handleCache (/home/rizwan/Documents/projects/todoapp/node_modules/ejs/lib/ejs.js:201:18)
    at tryHandleCache (/home/rizwan/Documents/projects/todoapp/node_modules/ejs/lib/ejs.js:223:14)
    at View.exports.renderFile [as engine] (/home/rizwan/Documents/projects/todoapp/node_modules/ejs/lib/ejs.js:437:10)
    at View.render (/home/rizwan/Documents/projects/todoapp/node_modules/express/lib/view.js:128:8)
    at tryRender (/home/rizwan/Documents/projects/todoapp/node_modules/express/lib/application.js:640:10)
    at Function.render (/home/rizwan/Documents/projects/todoapp/node_modules/express/lib/application.js:592:3)
    at ServerResponse.render (/home/rizwan/Documents/projects/todoapp/node_modules/express/lib/response.js:971:7)
0 Answers
Related