Reputation: 57
whenever I reload my website I get this error:
SyntaxError: Unexpected token ';' in /Users/<name>/Desktop/Web_Development/ejs-challenge/views/home.ejs while compiling ejs
this is my app.js:
//jshint esversion:6
const express = require("express");
const ejs = require("ejs");
const homeStartingContent = "<placeholder text>";
const contactContent = "<placeholder text>";
const aboutContent = "<placeholder text>";
const app = express();
let posts = [];
app.set('view engine', 'ejs');
app.use(express.json());
app.use(express.urlencoded({extended: true}));
app.use(express.static("public"));
app.get("/", function(req, res){
res.render("home.ejs", {homeContent: homeStartingContent,
posts: posts});
});
app.get("/about", function(req, res){
res.render("about.ejs", {aboutContent: aboutContent,});
});
app.get("/contact", function(req, res){
res.render("contact.ejs", {contactContent: contactContent,});
});
app.get("/compose", function(req, res){
res.render("compose.ejs");
});
app.post("/compose", function(req, res){
const post = {
title: req.body.postTitle,
body: req.body.postBody,
};
posts.push(post);
res.redirect("/");
});
app.listen(3000, function() {
consol
e.log("Server started on port 3000"); });
this is my ejs:
<%- include('partials/header') -%>
<h1>Home</h1>
<p><%= homeContent %> </p>
<% posts.forEach(post => %>
<h1> <%= post.title %> </h1>
<p> <%= post.body %> </p>
<% )) %>
<%- include('partials/footer') -%>
ejslint tells me this:
Unexpected token (6:9) in home.ejs
<h1><%= post.title %></h1>
^
I don't know how to fix it, I have already removed all of the ";" that was in my home.ejs file, I have tried to use a normal function as well, Ejslint is not very helpful at least for me .
Upvotes: 1
Views: 485
Reputation: 684
you have two enclosing brackets remove one
<% posts.forEach(post => %>
<h1> <%= post.title %> </h1>
<p> <%= post.body %> </p>
<% )) %>
change to this
<% posts.forEach(post => %>
<h1> <%= post.title %> </h1>
<p> <%= post.body %> </p>
<% ) %>
Upvotes: 2