如何在禁用历史记录保存的情况下运行Node.js CLI REPL?

问题描述 投票:0回答:1

我想测试Node.js REPL中我不太熟悉的JS / ES API,但是大多数时候我都不希望将任何东西保存到REPL历史文件中以供以后参考或研究。

此外,Node CLI REPL与大多数外壳程序不同,即使您在命令前面加上空格也会将其保存到历史记录中。

我用man nodenode --help检查了Node的手册页,大多数其他CLI REPL都没有--no-save这样的东西,唯一接近的地方是:

Environment variables:
     NODE_REPL_HISTORY file
             Path to the file used to store persistent REPL history.  The default path is ~/.node_repl_history, which is overridden by this variable.  Setting the value to an empty string
             ("" or " ") will disable persistent REPL history.
node.js command-line terminal command-line-interface read-eval-print-loop
1个回答
0
投票

您可以在启动节点之前将NODE_REPL_HISTORY临时设置为其他值(例如/dev/null),因此Node.js cli repl不会默认保存为默认的~/.node_repl_history

export NODE_REPL_HISTORY="/dev/null" && node

但是在节点退出后不要忘记unset NODE_REPL_HISTORY,以便下次您正常启动节点时,NODE_REPL_HISTORY默认为默认配置:

export NODE_REPL_HISTORY="/dev/null" && node && unset NODE_REPL_HISTORY

如果您不想每次都键入,则可以在shell的rc文件中的别名(命令)上方设置该行,例如nonode

alias nonode="export NODE_REPL_HISTORY="/dev/null" && node && unset NODE_REPL_HISTORY"

© www.soinside.com 2019 - 2024. All rights reserved.