- Learning Node.js Development
- Andrew Mead
- 166字
- 2021-06-30 18:56:59
Refactoring
In the previous section, you created the addNote function, which works well. It starts by creating some static variables, then we fetch any existing notes, we check for duplicates, and if there are none, we push it onto the list, and then we save the data back into the filesystem.
The only problem is that we'll be doing a lot of these steps over and over again for every method. For example, with getAll, the idea is to fetch all of the notes, and send them back to app.js so it can print them to the screen for the user. The first thing we'll to do inside of the getAll statement is have the same code; we'll have our try-catch block to fetch the existing notes.
Now, this is a problem because we'll be repeating code throughout the application. It will be best to break out the fetching of notes and the saving of notes into separate functions that we can call in multiple locations.
- 物聯網與北斗應用
- FreeSWITCH 1.2
- 網絡協議工程
- Spring Boot 2.0 Projects
- 物聯網安全與深度學習技術
- JBoss EAP6 High Availability
- 網絡的琴弦:玩轉IP看監控
- Getting Started with Grunt:The JavaScript Task Runner
- 中國互聯網發展報告2018
- C/C++串口通信:典型應用實例編程實踐
- 端到端QoS網絡設計
- 人人都該都懂的互聯網思維
- Getting Started with nopCommerce
- 移動物聯網:商業模式+案例分析+應用實戰
- Hands-On Bitcoin Programming with Python