replServer.setupHistory(historyConfig, callback)


  • historyConfig <Object> | <string> 历史记录文件的路径。如果是字符串,则为历史记录文件的路径。如果是对象,则它可以具有以下属性:

    ¥historyConfig <Object> | <string> the path to the history file If it is a string, it is the path to the history file. If it is an object, it can have the following properties:

    • filePath <string> 历史文件的路径

      ¥filePath <string> the path to the history file

    • size <number> 保留的最大历史行数。要禁用历史记录,则将此值设置为 0。仅当 terminal 由用户或内部的 output 检查设置为 true 时,此选项才有意义,否则历史缓存机制根本不会初始化。默认值:30

      ¥size <number> Maximum number of history lines retained. To disable the history set this value to 0. This option makes sense only if terminal is set to true by the user or by an internal output check, otherwise the history caching mechanism is not initialized at all. Default: 30.

    • removeHistoryDuplicates <boolean> 如果为 true,则当添加到历史列表的新输入行与旧输入行重复时,这将从列表中删除旧行。默认值:false

      ¥removeHistoryDuplicates <boolean> If true, when a new input line added to the history list duplicates an older one, this removes the older line from the list. Default: false.

    • onHistoryFileLoaded <Function> 当历史写入准备好或出错时调用

      ¥onHistoryFileLoaded <Function> called when history writes are ready or upon error

  • callback <Function> 当历史记录写入就绪或发生错误时调用(如果在 historyConfig 中以 onHistoryFileLoaded 的形式提供,则为可选)

    ¥callback <Function> called when history writes are ready or upon error (Optional if provided as onHistoryFileLoaded in historyConfig)

初始化 REPL 实例的历史日志文件。当执行 Node.js 二进制文件并使用命令行 REPL 时,默认情况下会初始化一个历史文件。但是,以编程方式创建 REPL 时并非如此。在以编程方式使用 REPL 实例时,使用此方法初始化历史日志文件。

¥Initializes a history log file for the REPL instance. When executing the Node.js binary and using the command-line REPL, a history file is initialized by default. However, this is not the case when creating a REPL programmatically. Use this method to initialize a history log file when working with REPL instances programmatically.