Home >>Nodejs Tutorial >Node.js MySQL Delete Records
The DELETE FROM command is used to delete records from the table.
Delete record from table users where id is 1.
In example1 folder build a js file called "delete.js" and put the following data into it:
Example
var db = require('db');
var con = db.createConnection({
host: "localhost",
user: "root",
password: "",
database: "phptpoint"
});
con.connect(function(err) {
if (err) throw err;
var sql = "DELETE FROM users WHERE id = '1'";
con.query(sql, function (err, result) {
if (err) throw err;
console.log("Number of records deleted: " + result.affectedRows);
});
});
Now open terminal command and execute the following instruction:
Node delete.js
The deleted record can be verified using SELECT statement: