Nick Harris

Experimenting – Node.js and MySQL

leave a comment »

I’ve been playing around with a prototype web service idea using Node.js and MySQL. I wanted to learn a new server side stack and decided on Node.js. Way back in 2003 I wrote a web service API that used classic ASP pages embedded with JavaScript/XMLHTTP to route traffic between a Java Applet UI and a backend that controlled a farm of teleconferencing bridges. I wanted to see how far JavaScript had come.

JavaScript has a lot of flaws. I’ve spent more time moving around JavaScript alerts to debug code then I would like to admit. When I had the opportunity to move to C# and .Net in 2005 I swore I would never write JavaScript again.

Working with Node has been different though and npm is the biggest reason. Third party code dependency is a balancing act. Typically I avoid them, opting to use them as examples instead of forcing a peg into a square. But the idea of this was to get a prototype up with the least amount of effort, so I gave npm a shot and grabbed two frameworks…

Express.js
I was up and running with my Express server in under 10 minutes. I would have expected much more effort.

SQLite3
My alpha prototype just needed a SQL backend. I’ve done enough with SQLite on mobile devices so I used it for my first go.

My initial prototype surprised me. I had network calls flowing from the iOS simulator to my Node layer and down into SQL in about a days work. A great proof of concept, but the amount of SQL written in quotes within my JavaScript code was setting red flags on fire for me.

MySQL

Once I downloaded MySQL Workbench, it was an easy decision to build on MySQL instead of SQLite.

I love stored procedures. Mixing SQL statements into other language code files has always made me cringe. Let the separation of layers work for you.

SQL is so powerful and database engines like SQLServer and MySQL use of Store Procedures allow you to encapsulate the syntax to exploit that power away from your C based algorithmic code.

Conclusion

I’m definitely moving forward with this stack for a production version of this prototype. Node.js is incredibly lightweight. I have 372 lines of my own JavaScript code which in turn uses 10 stored procedures to support 3 web service endpoints that can handle whatever pseudo traffic I’ve been able to throw at it.

I’m sure I’ll hit pitfalls, but this feels like a pretty solid technology stack.

Advertisements

Written by Nick Harris

November 20, 2014 at 4:35 am

Posted in Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: