Article: Using MySQL with Node.js & the node-mysql JavaScript Client

An excerpt from http://www.sitepoint.com/using-node-mysql-javascript-client/, by Jay Raj

NoSQL databases are all the rage these days and probably the preferred back-end for Node.js applications. But you shouldn’t architect your next project based on what’s hip and trendy, rather the type of database to be used should depend on the project’s requirements. If your project involves dynamic table creation, real time inserts etc. then NoSQL is the way to go, but on the other hand, if your project deals with complex queries and transactions, then a SQL make much more sense.

In this tutorial, we’ll have a look at getting started with the node-mysql module — a Node.js driver for MySQL, written in JavaScript. I’ll explain how to use the module to connect to a MySQL database, perform the usual CRUD operations, before examining stored procedures and escaping user input.

Installing node-mysql

node-mysql can be installed via npm. We can get up and running like so:

1 mkdir sp-node-mysql
2 cd sp-node-mysql
3 npm install mysql

If you need help using npm, then be sure to check out this article, or ask in our forums.

Continue reading this article on SitePoint

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.