express-workshop-all steps#5
express-workshop-all steps#5Behnazz wants to merge 1 commit intoCodeYourFuture:masterfrom Behnazz:master
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.
why are there all these backslashes in the JSON?
There was a problem hiding this comment.
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.
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.
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.
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.
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.
Please fix the JSON parsing and also complete the Handlebars part.
No description provided.