Node.js Version
v26.5.0
NPM Version
11.17.0
Operating System
Linux archlinux 7.0.8-arch1-1 #1 SMP PREEMPT_DYNAMIC Fri, 15 May 2026 16:45:15 +0000 x86_64 GNU/Linux
Subsystem
repl
Description
Description
When using the native Node.js binary REPL via terminal (node), multiline inputs (like objects, functions, or arrays) are correctly saved into .node_repl_history as a single physical line, where internal line breaks are represented by \r.
However, when creating a REPL instance programmatically using repl.start() and initializing history via repl.setupHistory(), every press of the Enter key triggers a write to the history file immediately. This breaks multiline inputs into separate, independent physical lines separated by \n. This completely breaks history navigation inside the programmatic REPL (pressing the Arrow Up key scrolls lines one by one instead of expanding the whole block).
Minimal Reproducible Example
Here is a short script demonstrating the issue:
import repl from 'node:repl';
import path from 'node:path';
const historyFile = path.join(import.meta.dirname, 'history.txt');
const r = repl.start({ prompt: '> ', terminal: true });
r.setupHistory(historyFile, () => {});
If you run this script and type a multiline array:
The resulting history.txt contains separate lines in reverse order:
While the native node history file combines them into a single line using \r:
Question
Is there a clean, official way to make a programmatic REPL handle multiline history exactly like the native CLI?
Minimal Reproduction
No response
Output
No response
Before You Submit
Node.js Version
v26.5.0
NPM Version
11.17.0
Operating System
Linux archlinux 7.0.8-arch1-1 #1 SMP PREEMPT_DYNAMIC Fri, 15 May 2026 16:45:15 +0000 x86_64 GNU/Linux
Subsystem
repl
Description
Description
When using the native Node.js binary REPL via terminal (
node), multiline inputs (like objects, functions, or arrays) are correctly saved into.node_repl_historyas a single physical line, where internal line breaks are represented by\r.However, when creating a REPL instance programmatically using
repl.start()and initializing history viarepl.setupHistory(), every press of theEnterkey triggers a write to the history file immediately. This breaks multiline inputs into separate, independent physical lines separated by\n. This completely breaks history navigation inside the programmatic REPL (pressing the Arrow Up key scrolls lines one by one instead of expanding the whole block).Minimal Reproducible Example
Here is a short script demonstrating the issue:
If you run this script and type a multiline array:
The resulting
history.txtcontains separate lines in reverse order:While the native node history file combines them into a single line using
\r:Question
Is there a clean, official way to make a programmatic REPL handle multiline history exactly like the native CLI?
Minimal Reproduction
No response
Output
No response
Before You Submit