Built a CRUD API for Robots with NodeJS, Express, and MongoDB

After building an API about myself I wanted to get into another API project right away. I found this article on Scotch.io about building a CRUD API using NodeJS, Express, and MongoDB. As I have been learning the MEAN stack I have put off working with MongoDB. In my previous attempts I had multiple issues setting it up and running it locally. I had enough issues that I put it off for too long. The Scotch.io tutorial mentioned a couple different online hosts for MongoDB databases, one of which is mLab. They offer a free instance that you can use as a sandbox database for development purposes. This was perfect to me as I want to learn how to interact with MongoDB, retrieving data and saving new data, but I’m not interested in learning how to admin or run a MongoDB instance. At least, not at this time. So, having a way to easily run Mongo and work with it was a definite catalyst to this project. It also lead to this tweet.

In the Scotch.io article it goes over the basic setup of Express and Mongoose. I used that as a template for getting my API up and running. It was a pretty straightforward process as I only needed one route with the appropriate handlers for each verb. Working with Mongoose was really easy and it worked to set it up on the route file. Working with the Mongoose docs made it easy to get my schema as ai wanted. In my API I used Robots as the example object I am creating, reading, updating, and deleting. I gave the object two custom parameters, designation and evil. Designation is a string and seemed more appropriate for a robot rather than calling it name. And it feels pretty important to know if a robot is evil or not, so I have that as well as a boolean. Each of these are given to the API via query strings. Being that I only have the two parameters I went with query strings in the URL instead of parsing out the body of the requests. In my next project I want to make a more complex object and that should lend itself to working with constructing custom objects to provide in the requests. Maybe that one can be superheroes. I can probably come up with a few more parameters for a superhero object.

It felt like the project went pretty smoothly and I was able to it up and running. I used Postman for testing out the routes and worked pretty well. I was able to run the requests as I needed and simulate a few error situations. I already know of one that I am not accounting for right now that needs to be addressed which is that requests will still go through to the POST route if neither of the parameters are supplied. It will end up with an empty object being created with no designation or evil params. I need to fix it so that the request is checked for both before I go to the database with nonexistent values.

Once that is fixed I will feel pretty good about the project. In fact I am likely going to fix it after I post this tonight. Next, I am work on an API for a more complex object. After that, I want to tackle adding in authentication so that I can have individual users. Right now anyone could use this API and it will all come in as one person.

If you want to check out the project you can find it on Github here. Feel free to let me know what you think in the comments here or submit PRs with your own ideas.

I made an API about myself as a web developer and human

I have really been focusing my efforts on learning web development on backend lately. It is the most interesting to me. I’m not really a fan of creating interfaces and dealing with moving elements of a page a few pixels at a time until it looks right on one of a million different devices. I just like making connections between things and moving data between them. I also rally enjoy making command line apps where I don’t have to worry about a UI, but that is for another post.

Since I have been focusing on backend / API work I figured it would be fun to build an API that could be used as a resource to learn about me and what I have done in my self-taught journey. It would help me learn further and would be a fun talking piece. Plus, I think it would be hilarious if someone asked for a resume and I gave them a URL for them to make a GET request to for the appropriate info.

I started out making a JSON object to describe me as a web developer. I also threw in some fun personal stuff to ensure someone making requests for it that I am indeed a human being. It was both weird and fun to create this data structure that is supposed to represent me. Once I had that mostly complete I installed Express to the project and began building out the routes for the API. This part was pretty simple as I am only supporting making GET requests for this API since I don’t want someone changing data about me unless it is me making the changes.

The necessary data for this API is pretty simplistic and since I don’t need to write new data or update existing via requests I decided that implementing a database like MongoDB would be overkill. Instead I decided on just creating JSON files with the necessary data for each route to return. I have a main route that provides a brief explanation of the API and the available endpoints. I have my resume style object in another JSON file. This way requests made to the appropriate endpoint will quickly return data. I even made a JSON file for custom errors that I require in each route file so that I can give a custom error message when someone attempts a request other than a GET.

Along with providing info about myself I also setup a /fun endpoint to provide info about fun things that can be done with the API. I am saving this part of the project for the silly ideas I have for micro-services to do hilariously “useful” things. The first one is /api/band-names which returns a listing of awesome band names I have created, each with their own id number. You can use /api/band-names/{{id}} to return a specific band name based on its id number. This spawned a separate project to create this object. Since I don’t have a database generating the id numbers for me I needed a way to create them. I keep this list of band names in a sheet in Smartsheet. I used the Auto-Number system column to generate unique five digit numbers for each name. Then I build a script that connects to the sheet and builds out an object with the id numbers and name. This object is then written out to a JSON file that I copied into my data directory along with the other necessary JSON files. Now, as I come up with other fun ideas for micro-services I can place them in as part of this API.

This was a really fun project to make and it helped me learn a lot more about Express and building out the backend of an app. Next up I am going to build out a simple CRUD API that connects to a MongoDB database. This will be a more typical API that handles GET / PUT / POST / DELETE requests. At first I was thinking that I would base it around the ideas of todos for a todo list, but instead I’m going to go with robots. That sounds more fun.

If you are interested in checking out my API about me you can find it here:


And the project can be found on Github here:


My first tech conference – WebDevCon

presentation space before the talk began
One of the talk rooms just before the keynote from Paul Duncan at WebDevCon.

Earlier this week, April 21st, I went to my first tech conference, WebDevCon. I heard about it from my Free Code Camp group and being free plus in my hometown I decided to go. To be honest, at first I wasn’t going to go, but Cassidy told me I should and I agreed with her. So I went and it was super fun! Having never gone to a tech conference I didn’t really know what to expect except for what I have read and seen online.
It was held at one of the Amazon buildings in South Lake Union here in Seattle, which was nice since this allowed me to walk to it. This conference is something that Amazon has been hosting internally since 2009 and this year was the first time they have opened it up to the public. It is a mostly front end focused conference and admittedly as I learn more I enjoy back end development more, but I still found the topics to be interesting and overall it was a great time.
I saw a few of the folks in my Free Code Camp group and also saw another friend of mine that works as a Java developer. The talks ranged from the performance of loading web fonts, to using observables to handle async issues, and keeping things as simple as possible in your workflow. That talk was the keynote given by Paul Duncan. He had some great points on keeping work simple and free of waste. He brought up a lot of kaizen practices and even called out the Toyota Production System as the prime example of creating waste free work. Cassidy loved hearing about this since that is her line of work at Virginia Mason now and they have a deep relationship with Toyota to create waste free work in the medical field.
My favorite talk was one given by Rachel White. Her talk was about her process making a robotic cat feeder titled Internet of Cats. The name had me, but I also saw it was built using NodeJS and Johnny-Five, so I had to check it out. Her talk was also about how scary it is to try something new and to put it out for all the world to see. She decided to make her project open source and she brought up some of the anxiety that can come from putting your thoughts and ideas out into the world for others to see and possibly judge very harshly. She gave some examples of things other developers she knows have gone through that has made them wary of working on open source software, but she also showed the awesomeness of others who have helped her on her project. It was a great talk on not only NodeBots, but also on the open source community itself and how it owes it to itself and its members to be a kind, respectful place. I really liked it.
Overall, the conference was a lot of fun. I got some stickers, a water bottle, and my brain filled with ideas on how the internet works.
This definitely makes me want to keep going to more conferences and web development type group talk/presentation things.

Being a part of Open Source Software – Moving Awesome Band Names to Github

I’ve been thinking a lot lately about finding ways to be part of the software development community at large. This blog and writing about my journey in code is one of them and the next is to start contributing to the world of open source software. It makes me happy to see a community of individuals putting their work out into the world for everyone to benefit, not just a select few. As my journey of learning to code continues and I work towards more advanced topics and projects it feels very natural to start contributing the code I write for others to see and possibly use.

To get started I am moving my recently published project, Awesome Band Names, to Github. Now anyone can easily see how I built it and offer their thoughts, be them criticism or praise. To get it up on Github I removed the Google Ad and the tweet button as those are a little self-serving in their purpose. I really just want the functionality I wrote to be available and the focus of any conversation on the project.

So, if you are interested in seeing it you can find the project on Github at http://daveskull81.github.io/awesome-band-names/. I still have the JS file in place to update the bandnames.js file with new names from the sheet I have, but that is ignored by Github. There isn’t a need to have that file published.

Now that I have this project out there I can start work on some of my other ideas. I will implement some v2 ideas for this project afterwards. There has been some stuff I’ve been working on lately for work that sadly can’t be published publicly as they are for internal processes. But, I do have some other ideas for other projects to work on that I will be putting on Github. It seems fitting to make a weather app, so that will be one of them and then I will use my Github user page for a portfolio site of sorts.

I’m trying to keep my mind really open to new ideas for projects. I also have a couple of goals that I have set my eyes on for the future, one easily attainable and the other will take a little more work. Being a part of the open source software community not only means putting out my own code for the world to see, but it also means adding value to the existing projects out there. One of the aspects of the open source world I really like is the community development. So, I am looking around for an open source project to submit some changes to. If you have any suggestions on a good place to start let me know in the comments. Everyone I have talked to has been really encouraging and told me to just go for it, find a project that needs something simple like a typo in a README adjusted and submit it. There is this stigma around the first pull request one makes and the fear of people getting mad at you for not knowing what you are doing. I definitely feel this sometimes, but I try to remind myself that we were all new to something once and you have to start somewhere. Besides, if someone gets mad at me for trying to help them they’re a dick and I can easily ignore them.

My other, more lofty, goal is to write and publish a module to NPM. I have no idea what it will do yet, but I’m thinking that once I find myself doing something over and over again that maybe I should write code that does it for me. Not only will that help me be more efficient, but that is probably a good candidate for this idea. On the plus side, other people might also be doing the same thing often and it could help them get the task done. I’m not in any rush on this one, it is just in the back of my mind for the future. I do want to get it completed in 2016 though, so I’m not working too slowly on it.

This feels like a great starting point for now and that I am on an awesome start to new fun/exciting/scary because it’s hard stuff. Huzzah!