Disable .node_repl_history file
Asked Answered
K

2

7

Is it possible to disable the node-history of read-eval-print-loop (REPL) stored in the .node_repl_history file in the home directory(~)?

Im using macOS High Sierra, and node is installed through home-brew.

Karilla answered 21/2, 2018 at 19:27 Comment(0)
O
4

You can disable it by setting the NODE_REPL_HISTORY environment variable to "".

You can read more about the environment variables and REPL in the Node.js documentation.

Ortiz answered 21/2, 2018 at 19:49 Comment(2)
Thanks! But where/how is this done? How do you set the NODE_REPL_HISTORY to "" ? In the bash shell or in the node shell, or must I edit a file somewhere?Karilla
There are a couple ways to do it on a mac: osxdaily.com/2015/07/28/set-enviornment-variables-mac-os-xOrtiz
A
1

You can temporarily disable node REPL history by running

var oldWrite = fs.write; var oldFs = fs; fs.write = () => {}; delete globalThis.fs; var fs = {...oldFs,write:oldWrite};
Note that this will only last until the REPL is closed and this will not disable reading history, only adding history.
Arva answered 5/8 at 20:28 Comment(4)
That's true... but it will also disable basically ALL file writes. How is this better than e.g. making an alias in .zshrc that just turns off the envar mentioned in the accepted answer? Something like alias incognode="NODE_REPL_HISTORY=\"\" && node"?Etiolate
Not All file writes, fs.writeSync will work just fine. But you do have a point, I have updated my answer to not break the local fs.write.Arva
And addressing how this answer is "better". It works on windows too. THAT'S ALL I GOT.Arva
Works for me, you should edit that into the question since Windows doesn't use envars like *nix. +1Etiolate

© 2022 - 2024 — McMap. All rights reserved.