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.

+3


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 .



+5


source


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         
    client.end();
});

      



There are other libraries that have slightly different APIs.

+4


source







All Articles