add solution of task node_form-data#160
add solution of task node_form-data#160Voloshynd wants to merge 6 commits intomate-academy:masterfrom
Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Thanks for your work! However, there's a critical issue: your code currently overwrites the entire db/expense.json file with only the latest expense, erasing all previous entries. To meet the requirements, you need to read the existing array of expenses, append the new one, and then write the updated array back to the file. Please fix this logic so that all expenses are preserved. You're almost there—keep going! 🚀
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Important
Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.
Tip
If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.
Caution
Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.
Footnotes
src/createServer.js
Outdated
| const writeStream = fs.createWriteStream(filePath); | ||
|
|
||
| writeStream.on('error', (err) => { | ||
| // eslint-disable-next-line no-console | ||
| console.error('Write error:', err.message); | ||
| }); | ||
|
|
||
| writeStream.on('finish', () => { | ||
| // eslint-disable-next-line no-console | ||
| console.log('Expense data written successfully.'); | ||
| }); | ||
|
|
||
| writeStream.write(jsonString); | ||
| writeStream.end(); |
There was a problem hiding this comment.
Issue: The code creates a write stream and writes only the new expense object to the file, overwriting the entire file. This will erase all previous expenses and only keep the latest one. You should read the existing expenses, append the new one, and then write the updated array back to the file. This is a critical logic error.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Great job! 🎉 Your implementation meets all the core requirements: the server serves the HTML form, handles POST requests, appends new expenses without overwriting previous ones, and returns a well-formatted HTML response. All previous issues have been resolved, and your solution is complete and correct. Keep up the excellent work!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
No description provided.