<commit_before>
var lineReader = require('line-reader');
var sys = require('sys');
var exec = require('child_process').exec;
var Promise = require('bluebird');

var moduleArr = []; 
var fileName = process.argv[2];

function storingModuleNames(){

var eachLine = Promise.promisify(lineReader.eachLine);

    eachLine(fileName, function(line) {
      if (line.indexOf('require') != -1){
      var regex = /require\(([^)]+)\)/g;
      var mat = regex.exec(line);

      mat[1] = mat[1].replace(/'/g, '');
      moduleArr.push(mat[1]);
    }
    }).then(function() {
      runningCommand(moduleArr);
    }).catch(function(err) {
      console.error(err);
    });
};

function runningCommand(modules){
    for (var module in modules){

      var globalCommand = 'npm install -g '+modules[module];
      var localCommand = 'npm install '+modules[module]+' --save';
      
      function puts(error, stdout, stderr) { sys.puts(stdout) }
      exec(globalCommand, puts);
      exec(localCommand, puts);
    }
  };

var compute = function() {

  return new Promise(function(resolve) {
            storingModuleNames();
        })
        .catch(function (e) {
            throw e;
        });
};

compute();<commit_msg>Added exception handling<commit_after>
var lineReader = require('line-reader');
var sys = require('sys');
var exec = require('child_process').exec;
var Promise = require('bluebird');

var moduleArr = []; 
var fileName = process.argv[2];

function storingModuleNames(){

var eachLine = Promise.promisify(lineReader.eachLine);

    eachLine(fileName, function(line) {
      if (line.indexOf('require') != -1){
      var regex = /require\(([^)]+)\)/g;
      var mat = regex.exec(line);

      mat[1] = mat[1].replace(/'/g, '');
      moduleArr.push(mat[1]);
    }
    }).then(function() {
      runningCommand(moduleArr);
    }).catch(function(err) {
      console.error(err);
    });
};

function runningCommand(modules){
    for (var module in modules){

      var globalCommand = 'npm install -g '+modules[module];
      var localCommand = 'npm install '+modules[module]+' --save';
      
      function puts(error, stdout, stderr) { sys.puts(stdout) }
      exec(globalCommand, puts);
      exec(localCommand, puts);
    }
  };

var compute = function() {

  return new Promise(function(resolve) {
          if(process.argv[2]!=null)
            storingModuleNames();
          else
            console.error('A filename should be passed as argument');
        })
        .catch(function (e) {
            throw e;
        });
};

compute();
{'fraction_non_alphanumeric': 0.16496865203761754, 'fraction_numerical': 0.004310344827586207, 'mean_word_length': 2.8799392097264436, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1927872', 'n_tokens_mistral': 789, 'n_tokens_neox': 770, 'n_words': 172}