Dark Mode
Image

Node.js MySQL Select Records

Example

Retrieve all data from the table "employees".

Create a js file named select.js having the following data in DBexample folder.

  1. var mysql = require('mysql');  
  2. var con = mysql.createConnection({  
  3. host: "localhost",  
  4. user: "root",  
  5. password: "12345",  
  6. database: "javatpoint"  
  7. });  
  8. con.connect(function(err) {  
  9. if (err) throw err;  
  10. con.query("SELECT * FROM employees", function (err, result) {  
  11. if (err) throw err;  
  12. console.log(result);  
  13. });  
  14. });  

Now open command terminal and run the following command:

  1. Node select.js  

Node.js select record 1

You can also use the statement:

  1. SELECT * FROM employees;  

Node.js select record 2

Comment / Reply From