Viewing a response to: @matthewdavid/saving-notes-to-a-json-file-day-six-of-the-complete-node-js-developer-course
Good to see nice consistent code layout :) Makes it easier to digest code when it feels familiar. Eating exceptions like this is not a good idea, you never know if it was failure in the reading or something else. Not sure the best solution for this bit, could even generate a note with the failure info? It is the sort of thing that comes back later to bite you. hth Woz ``` try { var notesString = fs.readFileSync('notes-data.json') notes = JSON.parse(notesString) } catch (e) { } ```
author | woz.software |
---|---|
permlink | re-matthewdavid-saving-notes-to-a-json-file-day-six-of-the-complete-node-js-developer-course-20170907t063203129z |
category | javascript |
json_metadata | {"tags":["javascript"],"app":"steemit/0.1"} |
created | 2017-09-07 06:32:03 |
last_update | 2017-09-07 06:32:03 |
depth | 1 |
children | 4 |
last_payout | 2017-09-14 06:32:03 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.022 HBD |
curator_payout_value | 0.007 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 505 |
author_reputation | 2,321,910,395,519 |
root_title | "Saving Notes to a JSON file: Day Six of "The Complete Node.js Developer Course"" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 14,120,526 |
net_rshares | 9,511,193,108 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
matthewdavid | 0 | 9,511,193,108 | 100% |
> Eating exceptions like this is not a good idea, you never know if it was failure in the reading or something else. I agree with this. Maybe you can try making it fail on purpose (trying to open a file that doesn't exist for example) and then `console.log(e)` so you can see what is returned. Normally when I catch errors I do `console.log(e.stack)`, and it gives enough explanation of what happened. Also, I learned how to use `.filter()` with your post and the further explanation that @kkomaz wrote.
author | jfuenmayor96 |
---|---|
permlink | re-wozsoftware-re-matthewdavid-saving-notes-to-a-json-file-day-six-of-the-complete-node-js-developer-course-20170910t220027175z |
category | javascript |
json_metadata | {"tags":["javascript"],"app":"steemit/0.1","users":["kkomaz"]} |
created | 2017-09-10 22:00:27 |
last_update | 2017-09-10 22:03:54 |
depth | 2 |
children | 0 |
last_payout | 2017-09-17 22:00:27 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 506 |
author_reputation | 1,765,327,312,641 |
root_title | "Saving Notes to a JSON file: Day Six of "The Complete Node.js Developer Course"" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 14,497,096 |
net_rshares | 0 |
I see what you are saying with this and I thought about it when going through this exercise. This section in the course left the code like this, but it makes sense to give some feedback if an error occurred. I think the next section will be refactoring this bit of code so that the logic can be reused by other functions. We'll see when I get there.
author | matthewdavid |
---|---|
permlink | re-wozsoftware-re-matthewdavid-saving-notes-to-a-json-file-day-six-of-the-complete-node-js-developer-course-20170908t032049695z |
category | javascript |
json_metadata | {"tags":["javascript"],"app":"steemit/0.1"} |
created | 2017-09-08 03:20:48 |
last_update | 2017-09-08 03:20:48 |
depth | 2 |
children | 2 |
last_payout | 2017-09-15 03:20:48 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 349 |
author_reputation | 2,155,255,892,877 |
root_title | "Saving Notes to a JSON file: Day Six of "The Complete Node.js Developer Course"" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 14,211,696 |
net_rshares | 5,807,306,112 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
woz.software | 0 | 5,807,306,112 | 100% |
Will be interesting to see what they propose is the correct way after the refactor :)
author | woz.software |
---|---|
permlink | re-matthewdavid-re-wozsoftware-re-matthewdavid-saving-notes-to-a-json-file-day-six-of-the-complete-node-js-developer-course-20170908t062815476z |
category | javascript |
json_metadata | {"tags":["javascript"],"app":"steemit/0.1"} |
created | 2017-09-08 06:28:15 |
last_update | 2017-09-08 06:28:15 |
depth | 3 |
children | 0 |
last_payout | 2017-09-15 06:28:15 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 85 |
author_reputation | 2,321,910,395,519 |
root_title | "Saving Notes to a JSON file: Day Six of "The Complete Node.js Developer Course"" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 14,222,930 |
net_rshares | 0 |
One other thing I noticed is there is no try/catch around the writing of the file so if that fails for whatever reason it will bubble up while the read is caught. Was that intentional?
author | woz.software |
---|---|
permlink | re-matthewdavid-re-wozsoftware-re-matthewdavid-saving-notes-to-a-json-file-day-six-of-the-complete-node-js-developer-course-20170908t063211023z |
category | javascript |
json_metadata | {"tags":["javascript"],"app":"steemit/0.1"} |
created | 2017-09-08 06:32:12 |
last_update | 2017-09-08 06:32:12 |
depth | 3 |
children | 0 |
last_payout | 2017-09-15 06:32:12 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 184 |
author_reputation | 2,321,910,395,519 |
root_title | "Saving Notes to a JSON file: Day Six of "The Complete Node.js Developer Course"" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 14,223,218 |
net_rshares | 0 |