old_contents: var captchagen = require('captchagen');
  var fs = require('fs');
  
  var dataFilePath = './output/data.csv';
  var imageOutputDir = './output/images/';
  var imageUrlPrefix = 'http://localhost:3000/';
  var times = +process.argv[2];
  
  // generate images
  var captchas = [];
  for (var i = 0; i < times; ++i) {
    var captcha = captchagen.create();
    var filePath = imageOutputDir + i.toString() + '.png';
    console.log(captcha.text(), filePath);
  
    captcha.generate();
  
    captcha.buffer((e, buffer) => {
      fs.writeFile(filePath, buffer);
    });
  
    captchas.push(captcha);
  }
  
  // generate csv
  var header = ['image', 'answer'].join(', ');
  var body = captchas.map((captcha, i) => [
    imageUrlPrefix + i.toString() + '.png',
    captcha.text()
  ].join(', '));
  var data = header + '\n' + body.join('\n');
  fs.writeFile(dataFilePath, data);
  
new_contents: var captchagen = require('captchagen');
  var fs = require('fs');
  
  var dataFilePath = './output/data.csv';
  var imageOutputDir = './output/images/';
  var imageUrlPrefix = 'http://localhost:3000/';
  var times = +process.argv[2];
  
  // remove old images
  fs.readdirSync(imageOutputDir).forEach((file) => {
    if (file.match(/\.png$/)) {
      fs.unlinkSync(imageOutputDir + file);
    }
  })
  
  // generate images
  var generateCaptcha = (filename) => {
    var captcha = captchagen.create();
    var filePath = imageOutputDir + filename;
  
    captcha.generate();
  
    captcha.buffer((e, buffer) => {
      fs.writeFile(filePath, buffer);
    });
  
    return captcha;
  };
  var captchas = [];
  for (var i = 0; i < times; ++i) {
    var filename = i.toString() + '.png';
    var captcha = generateCaptcha(filename);
    captchas.push(captcha);
    console.log(captcha.text(), filename);
  }
  
  // generate csv
  var header = ['image', 'answer'].join(',');
  var body = captchas.map((captcha, i) => [
    imageUrlPrefix + i.toString() + '.png',
    captcha.text()
  ].join(','));
  var data = header + '\n' + body.join('\n');
  fs.writeFile(dataFilePath, data);
  
subject: remove old images