NOTE: The API Git repository got scrambled and I had to start over. The link above is correct.
Well, I have decided that passing the response object through multiple call backs is going to be a little crazy. I had to add two return methods just for the getUserCount and processUser SQL Server calls/endpoints. They are both fairly simple and the code that resulted (in hind sight) is convoluted. It will turn into a spaghetti mess with more calls.
I found an excellent tutorial on the ‘basics’ of promises (see reference #1). Following this, I recreated its author’s code and was able to get a very small chain of calls in a simple API method. Very nice!
I then started walking down the path of adopting my existing code using the Tedious library, but I had some issues on the .on() event handlers. Every time I would reference the response object, it would be undefined. I suspect that these .on() event handlers need to be promises themselves. But in reading further, I discovered that someone had already made a Promise friendly version of the Tedious library (see reference #2). Following the instructions, I was very easily and quickly able to modify my TGIMBA Node JS API to use it.
Next post will be (ideally) with all of the other SQL methods implemented.