Check out example codes for "node mysql". It will help you in understanding the concepts better.

Code Example 1

var mysql = require('mysql');

var con = mysql.createConnection({
  
  host: "localhost",
  user: "yourusername",
  password: "yourpassword"

  });

con.connect(function(err) {
  if (err) throw err;
  console.log("Connected!");
});

Code Example 2

//put these lines in a seperate file
const mysql = require('mysql2');

const connection = mysql.createPool({
    host: "localhost",
    user: "",
    password: "",
    database: ""
    // here you can set connection limits and so on
});

module.exports = connection;

//put these on destination page
const connection = require('../util/connection');

async function getAll() {
    const sql = "SELECT * FROM tableName";
    const [rows] = await connection.promise().query(sql);
    return rows;
} 
exports.getAll = getAll;

Code Example 3

var mysql = require('mysql');

Code Example 4

con.connect(function(err) {
  if (err) throw err;
  console.log("Connected!");

   
  con.query(sql, function (err, result) {
    if (err) throw err;
    console.log("Result: 
  " + result);
  });
});

Code Example 5

const mysql = require('mysql');

const con = mysql.createConnection({
  
  host: "localhost",
  user: "yourusername",
  password: "yourpassword"

  });

con.connect(function(err) {
  if (err) throw err;
  console.log("Connected!");
});

Learn ReactJs, React Native from akashmittal.com