Node js MySQL delete data

DELETE Command is used to delete records from MySql table. Once the data is deleted, you can not recover them. So always be careful while deleting the existing table.


DELETE FROM Tablename [WHERE Clause];

In the given example, we have deleted record of id #2.


var mysql = require('mysql');
var con = mysql.createConnection({
    host: "hostname",
    user: "username",
    password: "password",
    database: "database"
    if(error) {
        console.log('Error establishing connection to db');
    console.log('Connection Established'); 
    var deletedata = "DELETE from department WHERE id = ?";
    con.query(deletedata, [2], function (error) {  
    if(error) { 
    console.log("Data Deleted");  

Open cmd and run the above file as -

nodejs mysql delete data

Read more articles

General Knowledge

Learn Popular Language