Putting it all together: “Pokemon Master”

Let’s serve up some Pokemon!!

This afternoon, all of the instructors left to participate in some team building activities. After being introduced to knex, we were left to our own devices with exercises to practice. Remember when I said I wanted to modify my Pokemon warmup to use routes? Well, I decided I would redo the exercise altogether.

I started an entirely new project called pokemon_master and decided to try to build up the express server from scratch. I wanted to implement everything we had gone over this week (and part of last week): express, REST, routes, express templating, and SQL/knex.

I wrote what I could remember from memory, but I did end up carefully copying and pasting chunks of code from the various other exercises we’ve been working on. It went fairly smoothly, but the first problem I ran into dealt with the templating. Since I implemented routing, I assumed all the templating stuff would need to go into the route file (routes/pokemon.js). After all, that’s the file that ends up rendering the pages. However, I got an error saying that ‘router’ (my express router variable in the aforementioned file) had no attribute/function ‘set.’ I then decided to try moving the three view/ejs-related lines into my server.js file, right before I call the middleware that uses the router. I was skeptical, but it worked. I may have to dig deeper to understand why. Templating in general is still a dark gray area in my mind. Maybe I just need to read more about it.

Some other issues I ran into: error handling. Due to the fact that the knex calls are promises (which I did not have any prior experience with), it wasn’t immediately clear to me how to go about sending the right status messages and when. I fiddled with it for a bit and finally got something that didn’t return errors and also behaved the way I wanted it to. Mostly. Still a minor kink in there that I think I’ll ask my instructor about tomorrow.

Definitely not *all* of the Pokemon. Clicking the sprites takes you to the Pokemon’s individual profile page.

I feel pretty good about being able to put it all together. I chose not to spend time styling the pages, I just wanted to make sure everything was hooked up properly on the backend. I have a strong feeling that when we learn Angular in the next quarter, it’s gonna make all of this pretty trivial.

On that note, I confess: I started doing the React tutorial on Code Academy. Holy smokes!! I only went through two modules but it’s already very clear how coding with React will streamline this whole process. I’ll try to be patient and not take a peek at Angular before we learn it in class.

Welp, that’s all I got for today. It’s almost Friday, hooray!

Like what you read? Give Sarah Hanson a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.