select mysql database records in node.js

The tutorial provides the node.js integration with MySQL to fetch / retrieve records from the mysql database using the node.js program. The tutorial provides the steps on how to select record from mysql table using node.js application.

Node.js Select Record from MySQL Table

The MySQL uses ‘SELECT * FROM’ statement for selecting records into mysql table. Ensure that you have the mysql table with records before proceeding with the record selection process. The WHERE Clause and Order by clause can also be used in the SQL Query which is given as an example below.

var mysql = require('mysql');  
var con = mysql.createConnection({  
  host: "localhost",  
  user: "root",  
  password: ""  ,
  database: "oracleappshelpDB"
});
con.connect(function(err) {
  if (err) throw err;
  con.query("SELECT * FROM oracleappshelpusers order by firstName",  function (err, result) {
    if (err) throw err;
    console.log(result);
  });
});
var mysql = require('mysql');  
var con = mysql.createConnection({  
  host: "localhost",  
  user: "root",  
  password: ""  ,
  database: "oracleappshelpDB"
});
con.connect(function(err) {
  if (err) throw err;
  con.query("SELECT * FROM oracleappshelpusers where firstName ='Mohit'",  function (err, result) {
    if (err) throw err;
    console.log(result);
  });
});
var mysql = require('mysql');  
var con = mysql.createConnection({  
  host: "localhost",  
  user: "root",  
  password: ""  ,
  database: "oracleappshelpDB"
});
con.connect(function(err) {
  if (err) throw err;
  con.query("SELECT * FROM oracleappshelpusers order by firstName",  function (err, result) {
    if (err) throw err;
    console.log(result);
  });
});

how to delete mysql database records in node.js

The tutorial provides the node.js integration with MySQL to delete record from the mysql table. The tutorial provides the steps on how to delete record from mysql database table using node.js application .

Delete Record from MySQL Table using node.js

The MySQL uses ‘DELETE FROM’ statement for deleting records into mysql table. Ensure that you have the mysql table with ecords before proceeding with the record deletion process.

var mysql = require('mysql');  
var con = mysql.createConnection({  
  host: "localhost",  
  user: "root",  
  password: ""  ,
  database: "oracleappshelpDB"
});
con.connect(function(err) {
  if (err) throw err;
  con.query("DELETE FROM oracleappshelpusers WHERE firstName = 'Amit'",  function (err, result) {
    if (err) throw err;
    console.log(result);
  });
})

Execute the SELECT SQL node.js program and it will show the remaining records now.