NodeJs Mysql Insert

Mysql Insert query – Insert into emp values (1,’delhi’);

Lets create a file “node-insert.js” with below code
var db = require('mysql');  
var con = db.createConnection({  
host: "localhost",  
user: "root",  
password: "password", 
database : "Student" 
});  
con.connect(function(err) {  
if (err) throw err;  
console.log("Connected!");  
var sqlQuery = "Insert into emp values (1,'delhi')";
con.query(sqlQuery, function (err, result) {  
if (err) throw err;  
console.log("Rows Inserted");  
});  
}); 


Below SS shows Output of this program.

node mysql insert query

Below SS shows output from Mysql.

node mysql insert output

Subscribe Now