Preserve command history in Node REPL
However, after exit and re-enter the REPL, all the previous commands are lost. This behaves very much different from what we expect from shell.
To maintain a persistent history, we can use rlwrap as suggested in this answer.
$ sudo apt-get install rlwrap
Create an alias:
alias node='env NODE_NO_READLINE=1 rlwrap -s 1000 -S "node> " node'
Persistent history file is saved in:
However, if by perserving the command history, Node REPL loses familiarity of color output and tab completion. This is a trade-off. To get around this problem, we can roll our own REPL or use an alternative. The best alternative I have found so far is also the one I am already using: CoffeeScript (see 1.6.3 change log). There is a history command built-in:
$ coffee coffee> .help .break Sometimes you get stuck, this gets you out .clear Break, and also clear the local context .exit Exit the repl .help Show repl options .history Show command history .load Load JS from a file into the REPL session .save Save all evaluated commands in this REPL session to a file