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.

Some of my favorite definitions of NPM

NPM is super awesome and I totes heart it. First coming into the world of Node.js and seeing the power of installing modules to add new functionality to my projects I was super excited. It also made sense when I heard or saw people call it “node package manager” since it was for loading and managing packages in Node.js.

But, I quickly learned how it was much more than that and how that definition limited how one could think about NPM. Most obvious is that even though NPM is bundled with Node.js you don’t have to use it solely in Node.js projects. It can be used to manage dependencies of a purely frontend workflow. You can also find lots of awesome CLI tools for making your shell life easier as well. I am also a huge fan of the purely silly packages that exist to bring smiles to people’s faces. I keep thinking about how I need to write more of these.

Through posts online and such I have seen that the folks who maintain NPM also feel the same way, that NPM is so much more than a Node.js package manager. On the NPM homepage you can see in the upper left corner a playful definition of what NPM stands for. It changes every time you load the page. I recently found myself refreshing the page repeatedly and taking screenshots of the ones that made me laugh the most.

So I present to you, my favorite “definitions” of NPM.

screen-shot-2016-06-22-at-8-51-47-pm

screen-shot-2016-11-05-at-3-29-24-pm

screen-shot-2016-11-05-at-3-30-35-pm

screen-shot-2016-11-05-at-3-31-04-pm

screen-shot-2016-11-05-at-3-31-18-pm

screen-shot-2016-11-05-at-3-34-36-pm

screen-shot-2016-11-05-at-3-44-59-pm

Going back to bash-ics with dev tools

I recently nuked my entire development environment and I did so purposefully. As I have been teaching myself to write code I have come across many fun, shiny things that can make developing for the web easier, flashier, or something-er. As someone new to the whole world I just kind of grabbed everything because people said it was cool and would fix so many problems. I also installed things at the advice of others I met who said a particular tool made something really easy for them.

Over time this has gotten me lots of cool things, but in the end it is LOTS of things. I recently read an article on Hackernoon regarding How it feels to learn JavaScript in 2016 and it got me thinking about my own dev setup. If you haven’t read it already I would suggest it because it is funny and sadly accurate at the same time. After reading it I began to think about my own development process and how I would make an app today if I was working on a project. It also reminded me of how a few months ago I erased my system and set everything up cleanly on my Mac. When I did this I made a list of all of my tools that I would need to install afterwards. I took great care to make sure I got all of these “important” items.

As I mentally went over what I have installed on my computer I realized that if someone asked me why I use a particular thing that I don’t think I could truly defend my choice in using it. I would likely start with a story of how I found out about the thing and read or was told how it solves a certain problem. If I was asked if I had experienced that problem I probably couldn’t say so for sure. For example, I was using Oh My ZSH on top of zshell instead of using bash as my shell in my Terminal app, which was Hyperterm instead of Terminal that comes with macOS. I was told awhile ago that Oh My ZSH was an awesome tool with these great configurable features, but it required using zshell. So, I changed the shell on my system and installed Oh My ZSH without ever really using bash and seeing how they are different and if I actually prefer one over the other.

This is also true of NVM, another tool I installed after reading a blog post. I understand the benefits of having multiple versions of Node on your system in case you need to develop apps using a particular version, but I have yet to actually have that need myself. It will likely come as I work more, but until then I am leaving it off.

Now, I have my shell set to bash, hence the awesome and pun-tastic title of this post, and I’ve uninstalled all of the things I can’t justify using. Going forward I plan on working on projects and as I experience the pitfalls of a certain process I can look into solutions for that issue. But, until then I am going to work with a more default setup. One benefit to this is that to get my dev environment setup on another computer will just take a .bashrc and .bash_profile along with installing Atom and Node.js. The contents of those bash files are stored in Google Keep, so I can easily copy and paste their contents into place. Fun fact, I have already replicated the things I was using and like about Oh My Zsh and zshell in bash. So, I probably won’t be switching back unless something pretty drastic comes up. I’m also using Terminal over Hyperterm.

In the end this is meant to help me solidify my learning in web development so that I can speak directly to the stuff that I am doing and why I am doing it.

Holy moly! I gave a talk about code I wrote!

As I have been teaching myself how to code I have been trying to go to various code meetups in the Seattle area. It is always fun to get into a room full of like minded individuals and hear people’s perspective on different web technologies. Most of them have talks of some kind where a couple people will present their idea on something in the realm of code. I have always wanted to give one and just recently got the opportunity to do it. I go to most of the BellevueJS meetups as they are usually pretty close to my work and are easy to get to after I leave the office.

A friend of mine, Matt, helps run it and after I put up my post regarding publishing my first package to NPM they asked me if I wanted to do a talk about that. I thought about it for a moment and said yes without really thinking about it. As I thought about it more the more it felt like a great idea. I have been wanting to do a talk about something and I could never really think of a topic. This would be a perfect subject for me to talk about as it is more about my getting over fears of putting code I wrote out into the world than the actual code itself.

So, I began preparing the presentation. I decided to keep it simple and had about five slides or so. Each one with a few talking points on them. I tried to keep it moving as I spoke and kept to the topics on the slides. I let the audience know that it was my first talk at the start which was more for me to get the nerves out than it was a disclaimer for them. It was a very receptive group and there was even a couple of questions for me afterwards. The group seemed to be mostly folks that are new to world of writing code, so it felt like a topic that resonated with them. At least it felt like it did to me.

I got some good feedback afterwards on the talk and on my package. Much like when I published the package it felt good to put myself out there. To be honest this was really more for myself than anything. Knowing that I could get up in front of a group of strangers and talk about code I wrote makes me feel really good about where I’m at as far as my learning in the field of web development. And also like the package, as simple as the presentation was, it felt great to get something out there. Now I can take what I’ve learned and use it for future things. I’m actually excited about the idea of speaking in front of people again. I plan on giving more talks about code and my views on it.

If you have ever wanted to give a talk about technology or really anything you feel passionate about I say do it. Take the leap and put yourself out there. It’s the only way to really know how it will make you feel.

I published my first package to NPM!

As I have been learning more and more about developing software for the web I have been wanting to be part of open source software and getting code I’ve written out in front of people. Part of that is writing about code here on this blog and another part is writing code and publishing it somewhere people can find it. I recently did a post about my plans to publish my first package to NPM and now I have done it, hooray! Just moments ago I published the package.

The package is an ExpressJS project boilerplate creator. It creates a simple directory structure along with some files to get started in creating an ExpressJS app. If you are interested in seeing it you can find the project here:

https://www.npmjs.com/package/express_project_boilerplate

I’ve done some basic testing and it works pretty well. There is on occasion errors that I have to look into, but running the package again seems to work. So, that should be fun to troubleshoot, yay!

But, really getting this project out in the world is really meant to be the catalyst for me to get over my fears of putting code I’ve written out there. It may not be the most sophisticated and it may not even be the best way to do this, but it is code I’ve written and it does the thing it is meant to do. That is pretty cool to me.

Let me know if you have any questions in the comments!

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.

I made a command line tool to lookup the weather

After typing in a zip code the results are shown on the command line.
After typing in a zip code the results are shown on the command line.

Now that I am putting the majority of my projects on Github I have been trying to come up with things to build. One of the first few things I set out to make was a command line app to get the current temperature based on a zip code. It is a simple node app that asks the user for a zip code, then looks up the current weather, and reports it back. I am using a couple of free APIs to make it happen. For the weather data I am using Forecast.io, but that requires a latitude and longitude to get the data. To get that based on a zip code I am using Zippopotam.us.
The basic flow of the app takes the user input using an npm package called Prompt and makes the request to Zippopotam.us. That returns a latitude and longitude for the zip code which is then passed into the call to Forecast.io along with a name for a city/town in the zip code.
The results are then printed out to the console in a basic sentence. I built something similar to this from a tutorial on NodeJS I did awhile back. I thought it would be a good starting point for getting up and running on Github as well as get me going on the “just build stuff” advice I get from basically everyone. I really liked the fact that this time around it was much easier to build and get working. I feel like I could have just built it in one sitting. I didn’t because I didn’t want to rush things, but it felt really good that this wasn’t as hard as I remember the tutorial being. It’s like I have actually learned a few things when it comes to building stuff in NodeJS.
If you want to see the code or even use the app yourself you can find the repo here. Feel free to submit a pull request if you come up with anything it needs.
I wouldn’t say this is complete, but it works pretty well. Let me know what you think!

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!

Something I built is on the internets!

Something I built is live on the internets for all to see, OMG! It isn’t much, but dagnabit it’s true. What I am gleefully kermit flailing over is the website I built, awesomebandname.com. It is a simple site where you can click or tap on a button to be given a random selection from my personally curated list of awesome band names. For the longest time I would hear something and think how it would make a great band name. I started collecting these together into a comprehensive list of awesomeness. At one point I was posting them in a series on an old blog of mine. These posts were always the most enjoyed by my few readers. That blog is no longer with us, but I still kept up the list.

After coming to work at Smartsheet I started keeping them in a sheet as my repository of awesomeness. It is three columns for names, source, and notes. The source column is for if I heard it said by someone else and it wasn’t thought of by me directly. As of this writing there are 183 entries.

I have been teaching myself web development for a couple of years now and I am at that not a beginner, but not quite advanced point where the only advice anyone gives to continue learning is to “just build stuff.” So, this seemed like a great idea for a project. It is really just a simple website rather than a fully fledged app, but it does the thing I built it to do.

Everything is laid out on the page with Bootstrap. The well gets a randomly selected band name placed within it on page load and there is a simple JQuery click event on the button that empties the well, chooses another randomly selected band name, and places that within the well. The random selection is done via a random number selection function that I got from MDN.

The JQuery looks like this:

$(document).ready(function() {
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min)) + min;
}
$('.nameDisplay').append(bandNames[getRandomInt(0,bandNames.length)]);
$('.nameButton').click(function() {
$('.nameDisplay').empty().append(bandNames[getRandomInt(0,bandNames.length)]);
});
});

The entire thing is two documents, one HTML file and a JS file that is the collection of band names in an array called bandNames. Bootstrap and JQuery are brought in by CDNs. I thought about having all of the band names in the html file to make it all work in a single document, but that didn’t seem worth it and I figure it would only clutter things up. I added a tweet button to make sharing easier and a Google ad, just in case this gets tweeted by Wil Wheaton or some other viral internet craziness type event happens. I figure it couldn’t hurt to get a few ad impressions while I’m at it. I did try to install a Facebook share button as well, but that wouldn’t show up on the page. To be honest, I didn’t spend much time troubleshooting why. I will be leaving that for v2 of the project.

My favorite part of the project is how I create the JS file with the array of band names. In the interest of dogfooding I keep all of the band names in a sheet in my Smartsheet account. Originally I was going to copy and paste the names into a JS file and manually make the array, which would have worked, but would have been boring and tedious. Updating it later on would have bothersome too with the possibility that I could miss one or have double entries. To keep this from happening I employed the Smartsheet API. Recently, the Smartsheet API has been given a JavaScript SDK that is written in NodeJS which just so happens to be the thing I am teaching myself and prefer to work within.

I have already been working with the Smartsheet API for fun so that part was pretty straight forward. I ended up writing a script that pulls down the content of the sheet, stringifies all of the entries, and then concatenates all of that into a file called bandnames.js. I was especially happy when I thought of making it write out the “var bandnames = [“ at the front and ending the file with “];” to finish off the array. Now, when I update my sheet I can run this script and I get a new JS file to put up on my server for the website. No worrying about if I missed one or entered one more than once, just a nice brand new JS file.

I wouldn’t say this project is done yet, but I am proud to say it is a good v1. Next, I need to fix the Facebook share button problem and also figure out why my Google ad isn’t displaying on mobile devices. I may also play around with the layout and overall design. My original intent was to use a Bootstrap theme that makes sites look like they were built in Geocities, but I changed my mind. I may still go back to a sillier design approach to go with the humorous intent of the site.

If you feel like checking it out go to awesomebandname.com. Note, that some of the names may contain some adult language and may be a little NSFW. Enjoy!

UPDATED
This project has been moved to Github! The links in the post have been updated. If you want you can find the project here:
http://daveskull81.github.io/awesome-band-names/

Find out more about the move in the post here.

I like coffee, code, and photography…

I like coffee, code, and photography…

Hello!

My name is david inden. As the subject of this post says, I like coffee, code, and photography. This is where I plan to talk about these things. I am teaching myself to develop web applications, brew coffee, and take photos, both digitally and with film. Here I will talk about these things as I learn from my mistakes and triumphs and probably also occasionally state an opinion about the world around me. I hope you will enjoy.
I make no promises to never be vulgar as that is sometimes unavoidable, but I can promise that I will always be honest. In the past I have put together several of these blog thingys and this time I think it can stick. I like the idea of putting myself and my thoughts/creations out there for anyone and most likely no one to read.
I will try to keep most posts within the bounds of my three subjects, but if I feel like talking about something I’m probably going to do it.
Other things I like are sci-fi/fantasy books/tv shows/movies, so expect me to fly my nerd flag proudly and I’m pretty sure I can work in a Star Trek or Old Man’s War reference into a post about cold brew, just sayin.
So, come along and join me on this fantastic adventure that is the journey to the center of my brain. WARNING: May be wet and/or squishy.