code: function history(repl, file) {
  
    try {
      var stat = fs.statSync(file);
      repl.rli.history = fs.readFileSync(file, 'utf-8').split('\n').reverse();
      repl.rli.history.shift();
      repl.rli.historyIndex = -1;
    } catch (e) {}
  
    var fd = fs.openSync(file, 'a'),
      reval = repl.eval;
  
    repl.rli.addListener('line', function(code) {
      if (code && code !== '.history') {
        fs.write(fd, code + '\n');
      } else {
        repl.rli.historyIndex++;
        repl.rli.history.pop();
      }
    });
  
    process.on('exit', function() {
      fs.closeSync(fd);
    });
  
    repl.commands['.history'] = {
      help: 'Show the history',
      action: function() {
        var out = [];
        repl.rli.history.forEach(function(v, k) {
          out.push(v);
        });
        repl.outputStream.write(out.reverse().join('\n') + '\n');
        repl.displayPrompt();
      }
    };
  }
docs: REPL History
  Pulled directly from https://github.com/tmpvar/repl.history
  with the slight tweak of setting historyIndex to -1 so that
  it works as expected.