Node.js Tutorial – Insert Record into MySQL Table

The tutorial provides the node.js integration with MySQL for inserting record into the mysql table. The tutorial provides the steps on how to insert new record into mysql table using node.js application .

Insert Record into MySQL Table using node.js

The MySQL uses ‘INSERT INTO ‘ statement for inserting records into mysql table. Ensure that you have the mysql table created before proceeding with the table record insertion process.

var mysql = require('mysql');  
var con = mysql.createConnection({  
  host: "localhost",  
  user: "root",  
  password: ""  ,
  database: "oracleappshelpDB"
});
con.connect(function(err) {
  if (err) throw err;
  console.log("MySQL Database oracleappshelpDB is Connected successfully!");
  var sql = "INSERT INTO oracleappshelpusers (firstName, lastName,address) VALUES ('Mohit', 'Sharma', 'Sydeny 2000')";
  con.query(sql, function (err, result) {
    if (err) throw err;
    console.log(" Record isnerted inot the table oracleappshelpUsers successfully...");
  });

});