use*_*379 5 ejs node.js express
Index.ejs写如下:
<% include ../views/partials/header %>
<ul>
<% todos.forEach(function(todo){ %>
<li><%= todo.text %> - <%= todo.body %></li>
<% }) %>
</ul>
<% include ../views/partials/footer %>
Run Code Online (Sandbox Code Playgroud)
我可以在console.log中记录数据库记录,但是我得到EJS文件的语法错误.
当我在控制台中运行节点app.js时,我在控制台中获得了以下内容.
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)
Run Code Online (Sandbox Code Playgroud)