Title: How to programmatically save multiline REPL history with \r (like native Node CLI)? · Issue #64508 · nodejs/node · GitHub
Open Graph Title: How to programmatically save multiline REPL history with \r (like native Node CLI)? · Issue #64508 · nodejs/node
X Title: How to programmatically save multiline REPL history with \r (like native Node CLI)? · Issue #64508 · nodejs/node
Description: Node.js Version v26.5.0 NPM Version 11.17.0 Operating System Linux archlinux 7.0.8-arch1-1 nodejs/help#1 SMP PREEMPT_DYNAMIC Fri, 15 May 2026 16:45:15 +0000 x86_64 GNU/Linux Subsystem repl Description Description When using the native No...
Open Graph Description: Node.js Version v26.5.0 NPM Version 11.17.0 Operating System Linux archlinux 7.0.8-arch1-1 nodejs/help#1 SMP PREEMPT_DYNAMIC Fri, 15 May 2026 16:45:15 +0000 x86_64 GNU/Linux Subsystem repl Descript...
X Description: Node.js Version v26.5.0 NPM Version 11.17.0 Operating System Linux archlinux 7.0.8-arch1-1 nodejs/help#1 SMP PREEMPT_DYNAMIC Fri, 15 May 2026 16:45:15 +0000 x86_64 GNU/Linux Subsystem repl Descript...
Opengraph URL: https://github.com/nodejs/node/issues/64508
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"How to programmatically save multiline REPL history with \\r (like native Node CLI)?","articleBody":"### Node.js Version\n\nv26.5.0\n\n### NPM Version\n\n11.17.0\n\n### Operating System\n\nLinux archlinux 7.0.8-arch1-1 nodejs/help#1 SMP PREEMPT_DYNAMIC Fri, 15 May 2026 16:45:15 +0000 x86_64 GNU/Linux\n\n### Subsystem\n\nrepl\n\n### Description\n\n### Description\n\nWhen 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`. \n\nHowever, 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).\n\n### Minimal Reproducible Example\n\nHere is a short script demonstrating the issue:\n\n```javascript\nimport repl from 'node:repl';\nimport path from 'node:path';\n\nconst historyFile = path.join(import.meta.dirname, 'history.txt');\n\nconst r = repl.start({ prompt: '> ', terminal: true });\nr.setupHistory(historyFile, () => {});\n```\n\nIf you run this script and type a multiline array:\n```javascript\n> [1,\n| 2]\n[ 1, 2 ]\n>\n```\n\nThe resulting `history.txt` contains separate lines in reverse order:\n```text\n2]\n[1,\n```\n\nWhile the native node history file combines them into a single line using `\\r`: \n```text\n2]\\r[1,\n```\n\n### Question\n\nIs there a clean, official way to make a programmatic REPL handle multiline history exactly like the native CLI?\n\n\n### Minimal Reproduction\n\n_No response_\n\n### Output\n\n_No response_\n\n### Before You Submit\n\n- [x] I have looked for issues that already exist before submitting this\n- [x] My issue follows the guidelines in the README file, and follows the 'How to ask a good question' guide at https://stackoverflow.com/help/how-to-ask","author":{"url":"https://github.com/psqq","@type":"Person","name":"psqq"},"datePublished":"2026-07-09T07:14:04Z","url":"https://github.com/nodejs/node/issues/64508"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:9e7668b8-07d5-d38c-eb84-f6eb8b8005ee |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C4C6:5463F:5C6775:7D2208:6AED2251 |
| html-safe-nonce | b3cbacd7937df96ad33bff672d6c8099497a13fabc964052c822cbe6ad759adb |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNEM2OjU0NjNGOjVDNjc3NTo3RDIyMDg6NkFFRDIyNTEiLCJ2aXNpdG9yX2lkIjoiNzY0NDA0OTM4NDk0MDU3NzM2MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | b8f1579c0482cc25bbb12d36169ebae0bc7838afd7631f4b55bc34d6b6578edc |
| hovercard-subject-tag | issue:4887123780 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/nodejs/node/64508/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c40ab480f5b48b4d07d621de582caaf1d6e1db1cb0d0196e890b59e21d441543/nodejs/node/issues/64508 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c40ab480f5b48b4d07d621de582caaf1d6e1db1cb0d0196e890b59e21d441543/nodejs/node/issues/64508 |
| og:image:alt | Node.js Version v26.5.0 NPM Version 11.17.0 Operating System Linux archlinux 7.0.8-arch1-1 nodejs/help#1 SMP PREEMPT_DYNAMIC Fri, 15 May 2026 16:45:15 +0000 x86_64 GNU/Linux Subsystem repl Descript... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | psqq |
| hostname | github.com |
| expected-hostname | github.com |
| None | e3e0f7f63e50c6fe879198a93a0a023a648ecc0a5e9bc3b5e033ac57172237e6 |
| turbo-cache-control | no-preview |
| go-import | github.com/nodejs/node git https://github.com/nodejs/node.git |
| octolytics-dimension-user_id | 9950313 |
| octolytics-dimension-user_login | nodejs |
| octolytics-dimension-repository_id | 27193779 |
| octolytics-dimension-repository_nwo | nodejs/node |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 27193779 |
| octolytics-dimension-repository_network_root_nwo | nodejs/node |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 707a24b346ac8a82878b9c084efaa38a997660cb |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width