Node.js MySQL: Delete Records
The MySQL DELETE FROM command removes one or more records from a table ÔÇö an essential part of CRUD operations. This guide shows you how to do it from Node.js using the mysql package.
Node.js Tutorial:-
SQL Tutorial:-
Example: Delete by City
// delete.js
var mysql = require('mysql');
var con = mysql.createConnection({
host: "localhost",
user: "root",
password: "12345",
database: "updategadh"
});
con.connect(function(err) {
if (err) throw err;
const sql = "DELETE FROM employees WHERE city = 'Delhi'";
con.query(sql, function (err, result) {
if (err) throw err;
console.log("Records deleted:", result.affectedRows);
});
});
Run It
node delete.js
Parameterized DELETE (Safer)
const sql = "DELETE FROM employees WHERE city = ?";
con.query(sql, ['Delhi'], (err, result) => {
if (err) throw err;
console.log(`${result.affectedRows} deleted`);
});
Verify
SELECT * FROM employees;
-- The Delhi rows should be gone
Important
Without a WHERE clause, DELETE removes ALL rows. Always include a condition unless you mean to empty the table.
Download New Real Time Projects:- Click here
Complete Advance AI topics:-
Conclusion
Deleting MySQL records from Node.js is one parameterized query. Use placeholders and always log affectedRows to confirm. For more tutorials, stay tuned to .
nodejs mysql delete
mysql delete query nodejs
node.js mysql delete
delete query in node js
delete a record mysql db
mysql delete join
node js mysql delete data
node js mysql delete records example