Mukarram Javid · Programing · 2 years ago

Bulk Insertion in MySQL with NodeJS (dynamic columns)

        

We will see insertion only. I will cover updation in another article.


To be honest, after reading this article you will be able to insert hundreds or thousands of records very quickly.


  • I assume you have initialized NodeJS environment.
  • In this practice module, I will use mysql2 npm package. 
  • In my case SQL table structure is:

    CREATE TABLE `customer` (
    `customerId` int NOT NULL AUTO_INCREMENT,
    `CustomerName` varchar(45) DEFAULT NULL,
    `CustomerAddress` varchar(45) DEFAULT NULL,
    PRIMARY KEY (`customerId`)
    );
  • You just need to install mysql2 from your terminal by using this command. In my case, I am using VS Code. Just wait to finish it.
npm i mysql2
  • After successfully install mysql2. You need to import it from mysql2 package.
const mysql2 = require('mysql2/promise')

In this scenario, I am using mysql using promises (async/await). We will not use .then().catch()



© 2024 - Built with Mukarram