If you’re integrating your Node.js service with MySQL, you probably want to execute queries.
I’ve seen a fair bit of ugly code to do this, often using callbacks. I thought I would share some of my own patterns here. Maybe this is useful to others to read.
I don’t typically use ORM’s. If you’re already happy with sequalize, this article is probably not for you.
Prequisites
The most popular NPM package for MySQL is mysql, but I use the mysql2 package instead.
The mysql2
package is also very popular, but has a
few advantages. The advantage I care about is support for
promises. The authors of this package have actually teamed up
with the authors of the mysql
package to …