Home >>Nodejs Tutorial >Node.js MySQL Select Records
Retrieve all data from the table "users". Select Command is to display/retrieve data.
Creates a js file called select.js with the following data in the folder example1.
Example
var db = require('db');
var con = db.createConnection({
host: "localhost",
user: "root",
password: "",
database: "phptpoint"
});
con.connect(function(err) {
if (err) throw err;
con.query("SELECT * FROM users", function (err, result) {
if (err) throw err;
console.log(result);
});
});
Now open terminal command and execute the following instruction:
Node select.js