Nodejs CSV data export system for users

I need to allow users to export their data in csv format. I have written app in nodejs. The export data for users can be huge. So i was wondering How to handle such situation in nodejs. Should i user process.nexttick or child process api of nodejs? Also are there any good module available for nodejs to convert data from mysql to csv.

read line by line from your mysql-db, and append line by line to your file

i dont know that much about the mysqlmodule, so i'm assuming here each line is just an array, therefore the 'row.join(';')'. if thats not the case (maybe its an object), you should fix that.

var fs = require('fs');
var connection = require('mysql').createConnection({yourdbsettingshere});

function processRow (row) {
  fs.appendFile('your-file.csv', row.join(';'), function (err) {
    connection.resume();
  });
}

var query = connection.query('SELECT * FROM WHATEVER');

query
  .on('error', function(err) {
    // do something when an error happens
  })
 .on('fields', function(fields) {
   processRow(fields);
 })
 .on('result', function(row) {
   // Pausing the connnection is useful if your processing involves I/O
   connection.pause();
   processRow(row, function (err) {
     connection.resume();
   });
 })
 .on('end', function() {
    // now you can mail your user
 });

if you have a lot of requests, you could use the compute-cluster module for distributing your workload