0

I'm a node.js beginner. I want to modify the behavior of node's default REPL, as decribed in this link, but I don't want to run a startup script because doing so starts the REPL without importing the existing history file. (I know this because I tried the code from the first answer: the modified REPL started, but prior history wasn't available.)

Is this possible? Or would it be easier to figure out how to add/import the existing history file and add said code to a startup script?

NOTE: I also tried using rlwrap with -H path/to/.node_repl.history, as suggested in this thread, combined with the script from the first link, and still no luck. I get the modified behavior, but no history.

Community
  • 1
  • 1
  • Is this not possible? Or is the answer so obvious that no-one will post it? – MonaLisaOverdrive Jul 17 '16 at 12:38
  • If a REPL allows editing of input lines (I don't know about `node`, but I suspect it does) you need to use the `-a` (or `--always-readline`) argument with `rlwrap`, otherwise `rlwrap` will remain "transparent" and not do anything useful. As in: `rlwrap -a -H /path/to/history node ` – Hans Lub Jul 22 '16 at 11:10
  • I did try rlwrap with -H and while I did retain history, I lost colorization. They've reverted the commit I referenced in the answer, so I'll probably wait for the next nodejs update and go back to using my alias workaround – MonaLisaOverdrive Jul 22 '16 at 13:13

1 Answers1

0

Don;t know if this is the 'right' way to do this, but it works for me:

Adding

alias node='node -e repl.repl.ignoreUndefined=true -i'

to my bashrc achieves the effect I'm looking for without clobbering existing history. I'm not sure how well this will work for changing multiple REPL defaults, so I'm not marking this as an answer yet.

UPDATE Unfortunately, the latest node.js update broke this. I believe this is the pull request responsible.