Learning Node.js has been in the back of my mind for awhile. It’s an in-demand skill, and its event-driven nature seems perfect for some ideas I have. Plus, all of the cool people are writing node.js.
A few weeks ago, the right forces came together to convince me that I should write a node.js app.
Writing a program is my favorite way to learn a programming language.
Spoiler: It was easier than I imagined.
With all of these thoughts stirring in me, and the boring winter months approaching, I decided to write a node.js app on the weekends.
What I Wrote
I wrote a middleware app which polls a server for some data. It then validates the data with the Amazon product advertising API, and then updates a mysql database (basic CRUD actions). The app runs continually and polls for this data at regular intervals.
This turned out to be good practice because I was able to make use of Node’s events and promises. I had to batch the validation process, since you can only lookup 10 items at a time.
The good news: the app was complex enough to create some bugs, and I found myself debugging the app in phpstorm. Setting up the debug configuration for a node.js app in phpstorm was super easy, and I was soon presented with the familiar debug panel.
Learning Resources I Used
I started by reading the Node Beginner and the Node Craftsman books by Manuel Kiessling. These books appealed to me because they’re aimed at developers who are familiar with other server-side languages like php, phython, or ruby.
Next, I did a bunch of googling and reading and figured out that I could write my app using ES6 classes. Yay!
Finally, once I got my app working, I realized that I needed to learn about deployment. I decided to use systemd to run my app as a service. The following resources were helpful:
Running your Node.js App with Systemd
Deploying Node.Js Apps with Systemd
I know those last 3 links sound similar, but I do recommend reading multiple guides when approaching an unfamiliar task. In this case, each one added a bit and between those and stack overflow, I got it figured out. I got my app up and running on ubuntu!
Interested in working with the Amazon Product Advertising API? Try “npm install apac”
My thanks goes out to the developers of the apac npm module. This module is a thin wrapper for Amazon’s product advertising API. If you are familiar with the API, you will likely find that module easy to work with, as I did!