node.js - 如何在禁用历史保存的情况下运行 Node.js CLI REPL?
问题描述
我喜欢在 Node.js REPL 中测试我/变得不太熟悉的 JS/ES API,但大多数时候我不希望将任何内容保存到 REPL 历史文件中以供以后参考或研究。
与大多数 shell 不同,Node CLI REPL 也是如此,即使您在命令前加上空格,它也会将其保存到历史记录中。
man node
我用and检查了 Node 的手册页node --help
,没有什么像--no-save
大多数其他 CLI REPL 那样,唯一接近它的是:
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 退出后,以便下次启动 Node 时通常NODE_REPL_HISTORY
默认为默认配置:
export NODE_REPL_HISTORY="/dev/null" && node && unset NODE_REPL_HISTORY
如果你不想每次都输入,你可以nonode
在你的 shell 的 rc 文件中设置别名(命令)上面的行:
alias nonode="export NODE_REPL_HISTORY="/dev/null" && node && unset NODE_REPL_HISTORY"
推荐阅读
- c++ - 如何使用可变参数模板转换每种变体类型
- c# - WPFApp 中的 DLLImport 不起作用(PInvokeStackImbalance)
- javascript - 如何在 Javascript 中将日期格式化为 2020 年 6 月 16 日星期一
- video - 复制到 matroska 的 FFMPEG mp4 丢失最后一帧
- python - 为什么我仍然得到 ManyToManyField 比较的旧值?
- git - 如何检查 git 存储库中哪些功能最常用
- c++ - 我可以有一个 ELI5 用于引用和指针以及何时使用它们吗?
- javascript - JavaScript - 按值和最多两个级别对数组进行分组
- amazon-web-services - 如何通过 Web 浏览器(不是控制台)使用 Amazon S3 存储桶
- php - 在 WooCommerce 的电子邮件中在表格下方重复的订单项目名称