Professional Documents
Culture Documents
js
let comments = [
{
id: uuid(),
username: 'Todd',
comment: 'lol that is so funny'
},
{
id: uuid(),
username: 'skyler',
comment: 'lol that is so great'
},
{
id: uuid(),
username: 'namesh',
comments: 'Nice'
},
{
id: uuid(),
username: 'vishal',
comment: 'woof woof'
},
})
app.listen(3000, () => {
console.log("I am listening at 3000")
})
views/comments folder
index.ejs
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Comments</title>
</head>
<body>
<h1> Comments</h1>
<ul>
<% for(let c of comments) {%>
<li>
<%= c.comment %> -<b>
<%= c.username %>
</b>
<a href="/comments/<%= c.id %> ">details</a>
</li>
<% } %>
</ul>
<a href="/comments/new">New Comments</a>
</body>
</html>
Show.ejs
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Show</title>
</head>
<body>
</body>
</html>
Edit.ejs
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Edit</title>
</head>
<body>
<h1>Edit</h1>
<form method="POST" action="/comments/<%= comment.id
%>?_method=PATCH">
<textarea name="comment" id="" cols="30" rows="10">
<%= comment.comment %></textarea>
<button>Save</button>
</form>
</body>
</html>
new.ejs
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>New Comments</title>
</head>
<body>
<h1>Make a new comment</h1>
<form action="/comments" method="POST">
<section>
<label for="username">Enter username</label>
<input type="text" id="username" placeholder="username"
name="username">
</section>
<section>
<label for="comment">Comment Text</label>
<br>
<textarea name="comment" id="comment" cols="30"
rows="5"></textarea>
</section>
<button>Submit</button>
</form>
<a href="/comments">Back to index</a>
</body>
</html>