create account

RE: Saving Notes to a JSON file: Day Six of "The Complete Node.js Developer Course" by woz.software

View this thread on: hive.blogpeakd.comecency.com

Viewing a response to: @matthewdavid/saving-notes-to-a-json-file-day-six-of-the-complete-node-js-developer-course

· @woz.software ·
$0.03
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) {

  }
```
👍  
properties (23)
authorwoz.software
permlinkre-matthewdavid-saving-notes-to-a-json-file-day-six-of-the-complete-node-js-developer-course-20170907t063203129z
categoryjavascript
json_metadata{"tags":["javascript"],"app":"steemit/0.1"}
created2017-09-07 06:32:03
last_update2017-09-07 06:32:03
depth1
children4
last_payout2017-09-14 06:32:03
cashout_time1969-12-31 23:59:59
total_payout_value0.022 HBD
curator_payout_value0.007 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length505
author_reputation2,321,910,395,519
root_title"Saving Notes to a JSON file: Day Six of "The Complete Node.js Developer Course""
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id14,120,526
net_rshares9,511,193,108
author_curate_reward""
vote details (1)
@jfuenmayor96 · (edited)
> 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.
properties (22)
authorjfuenmayor96
permlinkre-wozsoftware-re-matthewdavid-saving-notes-to-a-json-file-day-six-of-the-complete-node-js-developer-course-20170910t220027175z
categoryjavascript
json_metadata{"tags":["javascript"],"app":"steemit/0.1","users":["kkomaz"]}
created2017-09-10 22:00:27
last_update2017-09-10 22:03:54
depth2
children0
last_payout2017-09-17 22:00:27
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length506
author_reputation1,765,327,312,641
root_title"Saving Notes to a JSON file: Day Six of "The Complete Node.js Developer Course""
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id14,497,096
net_rshares0
@matthewdavid ·
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.
👍  
properties (23)
authormatthewdavid
permlinkre-wozsoftware-re-matthewdavid-saving-notes-to-a-json-file-day-six-of-the-complete-node-js-developer-course-20170908t032049695z
categoryjavascript
json_metadata{"tags":["javascript"],"app":"steemit/0.1"}
created2017-09-08 03:20:48
last_update2017-09-08 03:20:48
depth2
children2
last_payout2017-09-15 03:20:48
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length349
author_reputation2,155,255,892,877
root_title"Saving Notes to a JSON file: Day Six of "The Complete Node.js Developer Course""
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id14,211,696
net_rshares5,807,306,112
author_curate_reward""
vote details (1)
@woz.software ·
Will be interesting to see what they propose is the correct way after the refactor :)
properties (22)
authorwoz.software
permlinkre-matthewdavid-re-wozsoftware-re-matthewdavid-saving-notes-to-a-json-file-day-six-of-the-complete-node-js-developer-course-20170908t062815476z
categoryjavascript
json_metadata{"tags":["javascript"],"app":"steemit/0.1"}
created2017-09-08 06:28:15
last_update2017-09-08 06:28:15
depth3
children0
last_payout2017-09-15 06:28:15
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length85
author_reputation2,321,910,395,519
root_title"Saving Notes to a JSON file: Day Six of "The Complete Node.js Developer Course""
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id14,222,930
net_rshares0
@woz.software ·
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?
properties (22)
authorwoz.software
permlinkre-matthewdavid-re-wozsoftware-re-matthewdavid-saving-notes-to-a-json-file-day-six-of-the-complete-node-js-developer-course-20170908t063211023z
categoryjavascript
json_metadata{"tags":["javascript"],"app":"steemit/0.1"}
created2017-09-08 06:32:12
last_update2017-09-08 06:32:12
depth3
children0
last_payout2017-09-15 06:32:12
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length184
author_reputation2,321,910,395,519
root_title"Saving Notes to a JSON file: Day Six of "The Complete Node.js Developer Course""
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id14,223,218
net_rshares0