So, step 1 was to get some revision loaded up. Instead of apt-get or yum installing myself a version, I decided to get v8.11.3 (at this time is LTS) and install it in /usr/share/node. I symlinked all necessary executables to /usr/bin, and node -v’d myself to satisfactory execution.
004-rest-verbs.js: Cause we’re building something RESTful, I needed to think if I had access to some Verbs. Low and behold, after skimming the node.js api for http the .method was smack in my face. It really came down to RTFM.
005-list-add-remove.js: I just took off from there. We have access to a global, we can make logic decision based on methods passed, and now we can pass a querystring and parse it up! At this point things were looking fairly awesome.
006-post-list-add-remove.js: We can’t use querystring for long, so I had to convert it to data passed in the request. After reading how Events and EventEmitter worked, this seemed quite natural. Got into some try/catching as well, and now explicitly taking in JSON data as well. Just a couple steps away from what we need to actually do!
007-list-with-expired-items.js: At this point we needed to store data with some “life” tied to it. i had to kick in some setInterval logic to scan the list of items that we’re storing and cull any that have expired. I also approached a level of pride in my code by making it look more presentable. At this point of excitement I had decided to develop a dataloader to “test” how well it can load and purge data, as well as overall node.js performance.
008-persistent-executed-list.js: In loading node.js and terminating it I had to think ahead in “what to do if the process bombs out with data stored in it”. At this point I had plugged in two separate items:
A) process.on(), to hook in synchronous routines that saved data and performed any cleanup, and rightfully aborted the process.
B) fs.readFile() fs.writeFile, so that I can dump the “local memory storage” timely to disk in 30 seconds interval.