-
-
Notifications
You must be signed in to change notification settings - Fork 93
FV - Exercise finished #4
base: master
Are you sure you want to change the base?
Conversation
|
New pages |
| app.set("view engine", "handlebars"); | ||
|
|
||
| app.post("/subscribe", function(req, res) { | ||
| var email = req.fields.mail; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's better to use const or let instead of var
|
|
||
| // Write the file with the whole new content | ||
| fs.writeFile(__dirname + "/data/posts.json", newContent, function(error) { | ||
| res.end("success!"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in real life you'd send a JSON to the frontend, maybe something like:
{
status: 'SUCCESS'
}
| var mailingList = JSON.parse(content); | ||
|
|
||
| //Convert the object in an array with the emails | ||
| var emails = Object.keys(mailingList).map(function(key) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have you tried arrow functions? You could give it a try here!
|
|
||
| // array emails to handlebars | ||
| res.render("subscribers", { | ||
| subscribersMail: emails |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
| <h1>Subscribers - Mailing List</h1> | ||
|
|
||
| <ul> | ||
| {{#each subscribersMail}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
nennes
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good job! 👍
No description provided.