Home >>Nodejs Tutorial >Node.js MySQL Update Records

Node.js MySQL Update Records

Node.js MySQL Update Records

The UPDATE command is used in table updating records.


Update email in "users" table where id is 1.

Create a js file in DBexample folder named "update.js" and put the following data into it:

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 = "UPDATE users SET email = 'test@gmail.com' WHERE id = 1";  
con.query(sql, function (err, result) {  
if (err) throw err;  
console.log(result.affectedRows + " record(s) updated");  

Now open terminal command and execute the following command:

Node update.js

It will update the email id.

No Sidebar ads