title: Node js | MySql Insertion "Killed"
body: <p>I wrote the following <em>Node.js</em> Code for inserting millions of records into <em>MySQL</em>.</p>
  
  <pre><code>var mysql      = require('mysql');
  var fs         = require('fs');
  var csv        = require('fast-csv');
  
  var connection = mysql.createPool({
      user: 'root',
      password: '***********',
      host: 'localhost',
      port: 3306,
      database: '***********'
  });
  </code></pre>
  
  <p>Below,I am pooling the connection</p>
  
  <pre><code>var getConnection = function(callback) {
  connection.getConnection(function(err, connection) {
     callback(err, connection);
   });
  };
  var i = 1;
  
  csv
  .fromPath("company.csv")
  .on("data", function(data){
      data.forEach(function(item){
      getConnection(function(err, conn){
  
       conn.query('INSERT INTO postmeta (post_id, meta_key, meta_value) VALUES (1,"' + i +'","'+ item +'")', function(err, rows) {
         if(err){
         console.log(err);
         }
     });
   });
  });
  i = i + 1;
  })
   .on("end", function(){
    console.log("done");
    console.log(i);
  });
  </code></pre>
  
  <p>Although everything gets executed properly, nothing is inserted into the database!</p>
  
  <p>What is wrong with the code ?
  Any other solution for inserting huge amount of data into <em>MySQL</em> through <em>Node.js</em> ?</p>
  
  <p>Thanks in Advance !</p>