How to connect to MySQL using Node.js

If you want to use MySQL with your Node.js app here’s how to do it:

Install the MySQL

First of all go to https://npmjs.org/package/mysql to check the latest version. At the day of this post:

Connect to the MySQL

Now add the following lines somewhere at the top of your application:

Run a query

Use the following function to run a query. Notice the callback function you can use to retrieve rows, fields and errors.

I’ve used a for to go through all the returned results.

No comments yet, leave yours!

Leave a Reply

Add <code> Some Code </code> by using this tags.