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

Conversation

@Behnazz
Copy link

@Behnazz Behnazz commented Jul 17, 2018

No description provided.

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

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?

Copy link

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

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

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"] })
Copy link

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

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.

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.

Please fix the JSON parsing and also complete the Handlebars part.

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