My Sql Connection in Node Js CRUD Operation
Install Lib npm install mysql2 Connect My Sql Database const mysql = require ( 'mysql2' ) ; // Create a MySQL connection const db = mysql. createConnection ({ host : 'localhost' , // Your MySQL host user : 'root' , // Your MySQL username password : '' , // Your MySQL password database : 'mydatabase' // Your MySQL database name }) ; // Connect to the database db . connect ((err) => { if (err) { console . error ( 'Error connecting to MySQL:' , err) ; return; } console . log ( 'Connected to MySQL database.' ) ; }) ; //Promise function allow const dbPromise = db. promise () ; Insert Data async function InsertRecord (name) { const query = 'INSERT INTO reg (Name) VALUES (?)' ; try { const [result] = await dbPromise. query (query , [name]) ; // Execute the query console . log ( `Record inserted with roll: ${result. insertId } ` ) ; } catch (e...