我想测试Node.js REPL中我不太熟悉的JS / ES API,但是大多数时候我都不希望将任何东西保存到REPL历史文件中以供以后参考或研究。
此外,Node CLI REPL与大多数外壳程序不同,即使您在命令前面加上空格也会将其保存到历史记录中。
我用man node
和node --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_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"