How can I query MySQL using node.js?

I am going to make a client server application using Node.js and I want to use a MySQL database to store some data. I need to know how to query a database with server side JavaScript.


source to share

2 answers

Search for a module library for mysql and you will get many modules that will allow you to do this, including mysql , db-mysql and easy-mysql .



npm install node -mysql

var mysql = require('mysql'),
    client = mysql.createClient({
        user: 'root',
        password: 'root',

mysql.query('SELECT * FROM my_table', function(err, results, fields) {
    //have fun         


There are other libraries that have slightly different APIs.



All Articles