3

I am going to make a client-server application using Node.js, and I want to use a MySQL database for storing some of the data. I need to know how to query a database with server-side JavaScript.

2 Answers 2

5

Search the module library for mysql and you will get many modules that will let you do that including mysql, db-mysql, and easy-mysql.

Sign up to request clarification or add additional context in comments.

Comments

4

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 as well that all have slightly different APIs.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.