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

Conversation

@franciscavargas
Copy link

No description provided.

@franciscavargas
Copy link
Author

franciscavargas commented Jul 17, 2018

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

app.set("view engine", "handlebars");

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

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!");
Copy link

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) {
Copy link

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

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

Choose a reason for hiding this comment

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

👍

Copy link

@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