Skip to content
This repository was archived by the owner on Aug 17, 2024. It is now read-only.

FV - Exercise finished#4

Open
franciscavargas wants to merge 3 commits intoCodeYourFuture:masterfrom
franciscavargas:master
Open

FV - Exercise finished#4
franciscavargas wants to merge 3 commits intoCodeYourFuture:masterfrom
franciscavargas:master

Conversation

@franciscavargas
Copy link
Copy Markdown

No description provided.

@franciscavargas
Copy link
Copy Markdown
Author

franciscavargas commented Jul 17, 2018

New pages
/subscribe.html => form
/subscribers => mailing list of people registered on the form

Comment thread server.js
app.set("view engine", "handlebars");

app.post("/subscribe", function(req, res) {
var email = req.fields.mail;
Copy link
Copy Markdown

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

Comment thread server.js

// Write the file with the whole new content
fs.writeFile(__dirname + "/data/posts.json", newContent, function(error) {
res.end("success!");
Copy link
Copy Markdown

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'
}

Comment thread server.js
var mailingList = JSON.parse(content);

//Convert the object in an array with the emails
var emails = Object.keys(mailingList).map(function(key) {
Copy link
Copy Markdown

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!

Comment thread server.js

// array emails to handlebars
res.render("subscribers", {
subscribersMail: emails
Copy link
Copy Markdown

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}}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Copy Markdown

@nennes nennes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good job! 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants