Node.js MySQL Delete
MySQL package is used to delete data from table in mysql using node js.
DELETE mysql statement is used to delete data into table in mysql database.
Example :
const mysql = require('mysql');
const db = mysql.createConnection({
host: "localhost",
user: "root",
password: "*******",
database : "aryadb"
});
// connect to database
db.connect((err) => {
if (err) {
throw err;
}else{
console.log('Connected to database!');
db.query("delete from employee where emp_id=1", function (err, result) {
if (err) throw err;
console.log("Deleted record : "+result.affectedRows);
});
}
});
Write above code in server.js file and run this program as below.
D:\nodejs\website> node server.js
It gives output as below.
Deleted record : 1
Comments