demo_db_insert.js:
var mysql = require('mysql'); var con = mysql.createConnection({ host: "localhost", user: "myusername", password: "mypassword", database: "mydb" }); con.connect(function(err) { if (err) throw err; console.log("Connected!"); //Insert a record in the "customers" table: var sql = "INSERT INTO customers (name, address) VALUES ('Company Inc', 'Highway 37')"; con.query(sql, function (err, result) { if (err) throw err; console.log("1 record inserted"); }); });
C:\Users\My Name>node demo_db_insert.js
Connected!
1 record inserted