The array of records can easily be bulk inserted into the node.js. Before insertion, you have to convert it into an array of arrays.

BY Best Interview Question ON 18 Jul 2019

Example

var mysql = require('node-mysql');
var conn = mysql.createConnection({
     // your database connection
});

var sql = "INSERT INTO Test (name, email) VALUES ?";
var values = [
    ['best interview question', '[email protected]'],
    ['Admin', '[email protected]'],
];

conn.query(sql, [values], function(err) {
     if (err) throw err;
     conn.end();
});

Suggest An Answer