diff --git a/lib/internal/repl.js b/lib/internal/repl.js index 278035f61f49f1..790ca15d622b13 100644 --- a/lib/internal/repl.js +++ b/lib/internal/repl.js @@ -3,6 +3,9 @@ const Interface = require('readline').Interface; const REPL = require('repl'); const path = require('path'); +const fs = require('fs'); +const os = require('os'); +const debug = require('util').debuglog('repl'); module.exports = Object.create(REPL); module.exports.createInternalRepl = createRepl; @@ -63,7 +66,20 @@ function createRepl(env, opts, cb) { } function setupHistory(repl, historyPath, ready) { - const fs = require('fs'); + if (!historyPath) { + try { + historyPath = path.join(os.homedir(), '.node_repl_history'); + } catch (err) { + repl._writeToOutput('\nError: Could not get the home directory.\n' + + 'REPL session history will not be persisted.\n'); + repl._refreshLine(); + + debug(err.stack); + repl._historyPrev = _replHistoryMessage; + return ready(null, repl); + } + } + var timer = null; var writing = false; var pending = false;