-
-
Notifications
You must be signed in to change notification settings - Fork 93
express-workshop-all steps #5
base: master
Are you sure you want to change the base?
Conversation
| { | ||
| "1467390356291": "This is my very first blog post!" | ||
| } | ||
| ["[\"[\\\"[\\\\\\\"[\\\\\\\\\\\\\\\"[\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"{\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"1467390356291\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\": \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"This is my very first blog post!\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n}\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\",{\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"1531861103496\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\":\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"Hi\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"}]\\\\\\\\\\\\\\\",{\\\\\\\\\\\\\\\"1531861155200\\\\\\\\\\\\\\\":\\\\\\\\\\\\\\\"Hello\\\\\\\\\\\\\\\"}]\\\\\\\",{\\\\\\\"1531861738283\\\\\\\":\\\\\\\"check\\\\\\\"}]\\\",{\\\"1531861917411\\\":\\\"First\\\"}]\",{\"1531861944247\":\"second\"}]",{"1531861944627":"second"}] No newline at end of file |
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.
why are there all these backslashes in the JSON?
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.
this should just be an array of objects
|
|
||
| app.post("/create-post", function (req, res) { | ||
| fs.readFile(__dirname + "/data/posts.json", function (error, file) { | ||
| const parsedFile = JSON.parse(file); |
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.
you are turning the file contents into an object, why are you not adding the data to this object?
| fs.readFile(__dirname + "/data/posts.json", function (error, file) { | ||
| const parsedFile = JSON.parse(file); | ||
| var storage = []; | ||
| storage.push(file.toString()); |
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.
why push the entire file as a string into the array?
| const parsedFile = JSON.parse(file); | ||
| var storage = []; | ||
| storage.push(file.toString()); | ||
| storage.push({ [Date.now()]: req.fields["blogpost"] }) |
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.
not you have a array that contains a string representation of an array and another object. Not what you'd want.
| var storage = []; | ||
| storage.push(file.toString()); | ||
| storage.push({ [Date.now()]: req.fields["blogpost"] }) | ||
| fs.writeFile("./data/posts.json", JSON.stringify(storage), function (error) { |
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.
When you stringify this, you end up with the crazy contents in your file.
Make sure you have the correct object structure before writing it back into the file.
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.
Please fix the JSON parsing and also complete the Handlebars part.
No description provided.