An API coding practice with Node and Express making the 10 Genera of common endemic freshwater fish available.
Create an API using Node and Express to serve up some data. Users can use the text-input and button to get formatted client-side display, or the url https://madfish-api-100devs.herokuapp.com/api/fishGenus to fetch information from a fish.json file
- Gain familiarity and comfort using Node and Express to create an API capable of Read (GET) functionality
- Practice pushing to git and to Heroku for a live build.
- Continue to gain experience organizing code
- In addition to the base build, I added a JSON.parse(readFileSync()) to separate the json object from the server.js and main.js code
Straight forward Node and Express app following past examples of creating a server in Node and utilizing Express functionality to make the code more readable.
I preferred to have my data file (fish.json) separated from my server code. A little Googling revealed how to use the readFileSync from the 'fs' module, along with JSON.parse() to make that happen.
On top of having the user by able to enter a Madagascar Fish genus in the url to facilitate a GET request and have a three parameter object returned, I wanted to practice using the '/public' folder to have client-side JavaScript available to the user.
Changes were pushed to a github repository and then, when a function build was completed, pushed to Heroku.
- VSCode
- JavaScript
- Node
- Express
- Heroku
- #100Devs
- Timeular - for keeping the sessions short and productive and preventing burnout
- Brainscape - for putting all the lessons learned into a spaced repetition format
- Focusatwill - for the background music or ambient noise to keep going
While starting a Node and Express app is fairly straight forward, passing data back and forth between client-side JavaScript and server-side JavaScript you really need to pay attention to the json formatting.
That handling a 404 error is not as straight forward as I thought it might be (see Continued development)
I'd like to handle a 404 error a little more gracefully than just stranding the user. This would be implemented to handle an unknown or mis-typed fish genus.
- Website - Aleksei Saunders
- LinkedIn - Aleksei Saunders