{"$schema":"https://doc-kit.nodejs.org/schemas/api-doc/1.0.0.json","id":"readline","path":"/readline","type":"module","module":"readline","title":"Readline","introducedIn":"v0.10.0","sourceLink":{"path":"lib/readline.js","url":"https://github.com/nodejs/node/blob/HEAD/lib/readline.js"},"stability":{"index":"2","description":"Stable"},"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"The `node:readline` module provides an interface for reading data from a\n[Readable](stream.html#readable-streams) stream (such as [`process.stdin`](process.html#processstdin)) one line at a time.\n\nTo use the promise-based APIs:\n\n```mjs\nimport * as readline from 'node:readline/promises';\n```\n\n```cjs\nconst readline = require('node:readline/promises');\n```\n\nTo use the callback and sync APIs:\n\n```mjs\nimport * as readline from 'node:readline';\n```\n\n```cjs\nconst readline = require('node:readline');\n```\n\nThe following simple example illustrates the basic use of the `node:readline`\nmodule.\n\n```mjs\nimport * as readline from 'node:readline/promises';\nimport { stdin as input, stdout as output } from 'node:process';\n\nconst rl = readline.createInterface({ input, output });\n\nconst answer = await rl.question('What do you think of Node.js? ');\n\nconsole.log(`Thank you for your valuable feedback: ${answer}`);\n\nrl.close();\n```\n\n```cjs\nconst readline = require('node:readline');\nconst { stdin: input, stdout: output } = require('node:process');\n\nconst rl = readline.createInterface({ input, output });\n\nrl.question('What do you think of Node.js? ', (answer) => {\n  // TODO: Log the answer in a database\n  console.log(`Thank you for your valuable feedback: ${answer}`);\n\n  rl.close();\n});\n```\n\nOnce this code is invoked, the Node.js application will not terminate until the\n`readline.Interface` is closed because the interface waits for data to be\nreceived on the `input` stream.\n\n<a id='readline_class_interface'></a>","summary":"The `node:readline` module provides an interface for reading data from a Readable stream (such as `process.stdin`) one line at a time.","examples":[{"language":"mjs","displayName":null,"code":"import * as readline from 'node:readline/promises';"},{"language":"cjs","displayName":null,"code":"const readline = require('node:readline/promises');"},{"language":"mjs","displayName":null,"code":"import * as readline from 'node:readline';"},{"language":"cjs","displayName":null,"code":"const readline = require('node:readline');"},{"language":"mjs","displayName":null,"code":"import * as readline from 'node:readline/promises';\nimport { stdin as input, stdout as output } from 'node:process';\n\nconst rl = readline.createInterface({ input, output });\n\nconst answer = await rl.question('What do you think of Node.js? ');\n\nconsole.log(`Thank you for your valuable feedback: ${answer}`);\n\nrl.close();"},{"language":"cjs","displayName":null,"code":"const readline = require('node:readline');\nconst { stdin: input, stdout: output } = require('node:process');\n\nconst rl = readline.createInterface({ input, output });\n\nrl.question('What do you think of Node.js? ', (answer) => {\n  // TODO: Log the answer in a database\n  console.log(`Thank you for your valuable feedback: ${answer}`);\n\n  rl.close();\n});"}],"children":[{"kind":"class","id":"class-interfaceconstructor","name":"InterfaceConstructor","title":"Class: `InterfaceConstructor`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.104"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"extends":{"text":"EventEmitter","links":[{"name":"EventEmitter","href":"events.html#class-eventemitter","start":0,"end":12}]},"description":"Instances of the `InterfaceConstructor` class are constructed using the\n`readlinePromises.createInterface()` or `readline.createInterface()` method.\nEvery instance is associated with a single `input` [Readable](stream.html#readable-streams) stream and a\nsingle `output` [Writable](stream.html#writable-streams) stream.\nThe `output` stream is used to print prompts for user input that arrives on,\nand is read from, the `input` stream.","summary":"Instances of the `InterfaceConstructor` class are constructed using the `readlinePromises.createInterface()` or `readline.createInterface()` method. Every instance is associated with a single `input` Readable stream and a single `output` Writable stream. The `output` stream is used to print prompts for user input that arrives on, and is read from, the `input` stream.","examples":[],"children":[{"kind":"event","id":"event-close","name":"close","title":"Event: `'close'`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.98"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"parameters":[],"description":"The `'close'` event is emitted when one of the following occur:\n\n* The `rl.close()` method is called and the `InterfaceConstructor` instance has\n  relinquished control over the `input` and `output` streams;\n* The `input` stream receives its `'end'` event;\n* The `input` stream receives <kbd>Ctrl</kbd>+<kbd>D</kbd> to signal\n  end-of-transmission (EOT);\n* The `input` stream receives <kbd>Ctrl</kbd>+<kbd>C</kbd> to signal `SIGINT`\n  and there is no `'SIGINT'` event listener registered on the\n  `InterfaceConstructor` instance.\n\nThe listener function is called without passing any arguments.\n\nThe `InterfaceConstructor` instance is finished once the `'close'` event is\nemitted.","summary":"The `'close'` event is emitted when one of the following occur:","examples":[],"children":[]},{"kind":"event","id":"event-error","name":"error","title":"Event: `'error'`","scope":"module","overloadOf":null,"stability":null,"added":["v16.0.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"parameters":[],"description":"The `'error'` event is emitted when an error occurs on the `input` stream\nassociated with the `node:readline` `Interface`.\n\nThe listener function is called with an `Error` object passed as the single argument.","summary":"The `'error'` event is emitted when an error occurs on the `input` stream associated with the `node:readline` `Interface`.","examples":[],"children":[]},{"kind":"event","id":"event-line","name":"line","title":"Event: `'line'`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.98"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"parameters":[],"description":"The `'line'` event is emitted whenever the `input` stream receives an\nend-of-line input (`\\n`, `\\r`, or `\\r\\n`). This usually occurs when the user\npresses <kbd>Enter</kbd> or <kbd>Return</kbd>.\n\nThe `'line'` event is also emitted if new data has been read from a stream and\nthat stream ends without a final end-of-line marker.\n\nThe listener function is called with a string containing the single line of\nreceived input.\n\n```js\nrl.on('line', (input) => {\n  console.log(`Received: ${input}`);\n});\n```","summary":"The `'line'` event is emitted whenever the `input` stream receives an end-of-line input (`\\n`, `\\r`, or `\\r\\n`). This usually occurs when the user presses <kbd>Enter</kbd> or <kbd>Return</kbd>.","examples":[{"language":"js","displayName":null,"code":"rl.on('line', (input) => {\n  console.log(`Received: ${input}`);\n});"}],"children":[]},{"kind":"event","id":"event-history","name":"history","title":"Event: `'history'`","scope":"module","overloadOf":null,"stability":null,"added":["v15.8.0","v14.18.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"parameters":[],"description":"The `'history'` event is emitted whenever the history array has changed.\n\nThe listener function is called with an array containing the history array.\nIt will reflect all changes, added lines and removed lines due to\n`historySize` and `removeHistoryDuplicates`.\n\nThe primary purpose is to allow a listener to persist the history.\nIt is also possible for the listener to change the history object. This\ncould be useful to prevent certain lines to be added to the history, like\na password.\n\n```js\nrl.on('history', (history) => {\n  console.log(`Received: ${history}`);\n});\n```","summary":"The `'history'` event is emitted whenever the history array has changed.","examples":[{"language":"js","displayName":null,"code":"rl.on('history', (history) => {\n  console.log(`Received: ${history}`);\n});"}],"children":[]},{"kind":"event","id":"event-pause","name":"pause","title":"Event: `'pause'`","scope":"module","overloadOf":null,"stability":null,"added":["v0.7.5"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"parameters":[],"description":"The `'pause'` event is emitted when one of the following occur:\n\n* The `input` stream is paused.\n* The `input` stream is not paused and receives the `'SIGCONT'` event. (See\n  events [`'SIGTSTP'`](#event-sigtstp) and [`'SIGCONT'`](#event-sigcont).)\n\nThe listener function is called without passing any arguments.\n\n```js\nrl.on('pause', () => {\n  console.log('Readline paused.');\n});\n```","summary":"The `'pause'` event is emitted when one of the following occur:","examples":[{"language":"js","displayName":null,"code":"rl.on('pause', () => {\n  console.log('Readline paused.');\n});"}],"children":[]},{"kind":"event","id":"event-resume","name":"resume","title":"Event: `'resume'`","scope":"module","overloadOf":null,"stability":null,"added":["v0.7.5"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"parameters":[],"description":"The `'resume'` event is emitted whenever the `input` stream is resumed.\n\nThe listener function is called without passing any arguments.\n\n```js\nrl.on('resume', () => {\n  console.log('Readline resumed.');\n});\n```","summary":"The `'resume'` event is emitted whenever the `input` stream is resumed.","examples":[{"language":"js","displayName":null,"code":"rl.on('resume', () => {\n  console.log('Readline resumed.');\n});"}],"children":[]},{"kind":"event","id":"event-sigcont","name":"SIGCONT","title":"Event: `'SIGCONT'`","scope":"module","overloadOf":null,"stability":null,"added":["v0.7.5"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"parameters":[],"description":"The `'SIGCONT'` event is emitted when a Node.js process previously moved into\nthe background using <kbd>Ctrl</kbd>+<kbd>Z</kbd> (i.e. `SIGTSTP`) is then\nbrought back to the foreground using [`fg(1p)`](http://man7.org/linux/man-pages/man1/fg.1p.html).\n\nIf the `input` stream was paused *before* the `SIGTSTP` request, this event will\nnot be emitted.\n\nThe listener function is invoked without passing any arguments.\n\n```js\nrl.on('SIGCONT', () => {\n  // `prompt` will automatically resume the stream\n  rl.prompt();\n});\n```\n\nThe `'SIGCONT'` event is *not* supported on Windows.","summary":"The `'SIGCONT'` event is emitted when a Node.js process previously moved into the background using <kbd>Ctrl</kbd>+<kbd>Z</kbd> (i.e. `SIGTSTP`) is then brought back to the foreground using `fg(1p)`.","examples":[{"language":"js","displayName":null,"code":"rl.on('SIGCONT', () => {\n  // `prompt` will automatically resume the stream\n  rl.prompt();\n});"}],"children":[]},{"kind":"event","id":"event-sigint","name":"SIGINT","title":"Event: `'SIGINT'`","scope":"module","overloadOf":null,"stability":null,"added":["v0.3.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"parameters":[],"description":"The `'SIGINT'` event is emitted whenever the `input` stream receives\na <kbd>Ctrl+C</kbd> input, known typically as `SIGINT`. If there are no\n`'SIGINT'` event listeners registered when the `input` stream receives a\n`SIGINT`, the `'pause'` event will be emitted.\n\nThe listener function is invoked without passing any arguments.\n\n```js\nrl.on('SIGINT', () => {\n  rl.question('Are you sure you want to exit? ', (answer) => {\n    if (answer.match(/^y(es)?$/i)) rl.pause();\n  });\n});\n```","summary":"The `'SIGINT'` event is emitted whenever the `input` stream receives a <kbd>Ctrl+C</kbd> input, known typically as `SIGINT`. If there are no `'SIGINT'` event listeners registered when the `input` stream receives a `SIGINT`, the `'pause'` event will be emitted.","examples":[{"language":"js","displayName":null,"code":"rl.on('SIGINT', () => {\n  rl.question('Are you sure you want to exit? ', (answer) => {\n    if (answer.match(/^y(es)?$/i)) rl.pause();\n  });\n});"}],"children":[]},{"kind":"event","id":"event-sigtstp","name":"SIGTSTP","title":"Event: `'SIGTSTP'`","scope":"module","overloadOf":null,"stability":null,"added":["v0.7.5"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"parameters":[],"description":"The `'SIGTSTP'` event is emitted when the `input` stream receives\na <kbd>Ctrl</kbd>+<kbd>Z</kbd> input, typically known as `SIGTSTP`. If there are\nno `'SIGTSTP'` event listeners registered when the `input` stream receives a\n`SIGTSTP`, the Node.js process will be sent to the background.\n\nWhen the program is resumed using [`fg(1p)`](http://man7.org/linux/man-pages/man1/fg.1p.html), the `'pause'` and `'SIGCONT'` events\nwill be emitted. These can be used to resume the `input` stream.\n\nThe `'pause'` and `'SIGCONT'` events will not be emitted if the `input` was\npaused before the process was sent to the background.\n\nThe listener function is invoked without passing any arguments.\n\n```js\nrl.on('SIGTSTP', () => {\n  // This will override SIGTSTP and prevent the program from going to the\n  // background.\n  console.log('Caught SIGTSTP.');\n});\n```\n\nThe `'SIGTSTP'` event is *not* supported on Windows.","summary":"The `'SIGTSTP'` event is emitted when the `input` stream receives a <kbd>Ctrl</kbd>+<kbd>Z</kbd> input, typically known as `SIGTSTP`. If there are no `'SIGTSTP'` event listeners registered when the `input` stream receives a `SIGTSTP`, the Node.js process will be sent to the background.","examples":[{"language":"js","displayName":null,"code":"rl.on('SIGTSTP', () => {\n  // This will override SIGTSTP and prevent the program from going to the\n  // background.\n  console.log('Caught SIGTSTP.');\n});"}],"children":[]},{"kind":"method","id":"rlclose","name":"close","title":"`rl.close()`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.98"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":null},"description":"The `rl.close()` method closes the `InterfaceConstructor` instance and\nrelinquishes control over the `input` and `output` streams. When called,\nthe `'close'` event will be emitted.\n\nCalling `rl.close()` does not immediately stop other events (including `'line'`)\nfrom being emitted by the `InterfaceConstructor` instance.","summary":"The `rl.close()` method closes the `InterfaceConstructor` instance and relinquishes control over the `input` and `output` streams. When called, the `'close'` event will be emitted.","examples":[],"children":[]},{"kind":"method","id":"rlsymboldispose","name":"[Symbol.dispose]","title":"`rl[Symbol.dispose]()`","scope":"module","overloadOf":null,"stability":null,"added":["v23.10.0","v22.15.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":null},"description":"Alias for `rl.close()`.","summary":"Alias for `rl.close()`.","examples":[],"children":[]},{"kind":"method","id":"rlpause","name":"pause","title":"`rl.pause()`","scope":"module","overloadOf":null,"stability":null,"added":["v0.3.4"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":null},"description":"The `rl.pause()` method pauses the `input` stream, allowing it to be resumed\nlater if necessary.\n\nCalling `rl.pause()` does not immediately pause other events (including\n`'line'`) from being emitted by the `InterfaceConstructor` instance.","summary":"The `rl.pause()` method pauses the `input` stream, allowing it to be resumed later if necessary.","examples":[],"children":[]},{"kind":"method","id":"rlpromptpreservecursor","name":"prompt","title":"`rl.prompt([preserveCursor])`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.98"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"preserveCursor","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"If `true`, prevents the cursor placement from\nbeing reset to `0`.","default":null,"optional":true,"rest":false,"properties":[]}],"returns":null},"description":"The `rl.prompt()` method writes the `InterfaceConstructor` instances configured\n`prompt` to a new line in `output` in order to provide a user with a new\nlocation at which to provide input.\n\nWhen called, `rl.prompt()` will resume the `input` stream if it has been\npaused.\n\nIf the `InterfaceConstructor` was created with `output` set to `null` or\n`undefined` the prompt is not written.","summary":"The `rl.prompt()` method writes the `InterfaceConstructor` instances configured `prompt` to a new line in `output` in order to provide a user with a new location at which to provide input.","examples":[],"children":[]},{"kind":"method","id":"rlresume","name":"resume","title":"`rl.resume()`","scope":"module","overloadOf":null,"stability":null,"added":["v0.3.4"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":null},"description":"The `rl.resume()` method resumes the `input` stream if it has been paused.","summary":"The `rl.resume()` method resumes the `input` stream if it has been paused.","examples":[],"children":[]},{"kind":"method","id":"rlsetpromptprompt","name":"setPrompt","title":"`rl.setPrompt(prompt)`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.98"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"prompt","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"returns":null},"description":"The `rl.setPrompt()` method sets the prompt that will be written to `output`\nwhenever `rl.prompt()` is called.","summary":"The `rl.setPrompt()` method sets the prompt that will be written to `output` whenever `rl.prompt()` is called.","examples":[],"children":[]},{"kind":"method","id":"rlgetprompt","name":"getPrompt","title":"`rl.getPrompt()`","scope":"module","overloadOf":null,"stability":null,"added":["v15.3.0","v14.17.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"the current prompt string"}},"description":"The `rl.getPrompt()` method returns the current prompt used by `rl.prompt()`.","summary":"The `rl.getPrompt()` method returns the current prompt used by `rl.prompt()`.","examples":[],"children":[]},{"kind":"method","id":"rlwritedata-key","name":"write","title":"`rl.write(data[, key])`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.98"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"data","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"key","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[{"name":"ctrl","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"`true` to indicate the <kbd>Ctrl</kbd> key.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"meta","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"`true` to indicate the <kbd>Meta</kbd> key.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"shift","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"`true` to indicate the <kbd>Shift</kbd> key.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"name","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"The name of the a key.","default":null,"optional":false,"rest":false,"properties":[]}]}],"returns":null},"description":"The `rl.write()` method will write either `data` or a key sequence identified\nby `key` to the `output`. The `key` argument is supported only if `output` is\na [TTY](tty.html) text terminal. See [TTY keybindings](#tty-keybindings) for a list of key\ncombinations.\n\nIf `key` is specified, `data` is ignored.\n\nWhen called, `rl.write()` will resume the `input` stream if it has been\npaused.\n\nIf the `InterfaceConstructor` was created with `output` set to `null` or\n`undefined` the `data` and `key` are not written.\n\n```js\nrl.write('Delete this!');\n// Simulate Ctrl+U to delete the line written previously\nrl.write(null, { ctrl: true, name: 'u' });\n```\n\nThe `rl.write()` method will write the data to the `readline` `Interface`'s\n`input` *as if it were provided by the user*.","summary":"The `rl.write()` method will write either `data` or a key sequence identified by `key` to the `output`. The `key` argument is supported only if `output` is a TTY text terminal. See TTY keybindings for a list of key combinations.","examples":[{"language":"js","displayName":null,"code":"rl.write('Delete this!');\n// Simulate Ctrl+U to delete the line written previously\nrl.write(null, { ctrl: true, name: 'u' });"}],"children":[]},{"kind":"method","id":"rlsymbolasynciterator","name":"[Symbol.asyncIterator]","title":"`rl[Symbol.asyncIterator]()`","scope":"module","overloadOf":null,"stability":null,"added":["v11.4.0","v10.16.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v11.14.0","v10.17.0"],"prUrl":"https://github.com/nodejs/node/pull/26989","commit":null,"description":"Symbol.asyncIterator support is no longer experimental."}],"signature":{"parameters":[],"returns":{"type":{"text":"AsyncIterator","links":[{"name":"AsyncIterator","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/AsyncIterator","start":0,"end":13}]},"description":""}},"description":"Create an `AsyncIterator` object that iterates through each line in the input\nstream as a string. This method allows asynchronous iteration of\n`InterfaceConstructor` objects through `for await...of` loops.\n\nErrors in the input stream are not forwarded.\n\nIf the loop is terminated with `break`, `throw`, or `return`,\n[`rl.close()`](#rlclose) will be called. In other words, iterating over a\n`InterfaceConstructor` will always consume the input stream fully.\n\nPerformance is not on par with the traditional `'line'` event API. Use `'line'`\ninstead for performance-sensitive applications.\n\n```js\nasync function processLineByLine() {\n  const rl = readline.createInterface({\n    // ...\n  });\n\n  for await (const line of rl) {\n    // Each line in the readline input will be successively available here as\n    // `line`.\n  }\n}\n```\n\n`readline.createInterface()` will start to consume the input stream once\ninvoked. Having asynchronous operations between interface creation and\nasynchronous iteration may result in missed lines.","summary":"Create an `AsyncIterator` object that iterates through each line in the input stream as a string. This method allows asynchronous iteration of `InterfaceConstructor` objects through `for await...of` loops.","examples":[{"language":"js","displayName":null,"code":"async function processLineByLine() {\n  const rl = readline.createInterface({\n    // ...\n  });\n\n  for await (const line of rl) {\n    // Each line in the readline input will be successively available here as\n    // `line`.\n  }\n}"}],"children":[]},{"kind":"property","id":"rlline","name":"line","title":"`rl.line`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.98"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v15.8.0","v14.18.0"],"prUrl":"https://github.com/nodejs/node/pull/33676","commit":null,"description":"Value will always be a string, never undefined."}],"type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"default":null,"description":"The current input data being processed by node.\n\nThis can be used when collecting input from a TTY stream to retrieve the\ncurrent value that has been processed thus far, prior to the `line` event\nbeing emitted. Once the `line` event has been emitted, this property will\nbe an empty string.\n\nBe aware that modifying the value during the instance runtime may have\nunintended consequences if `rl.cursor` is not also controlled.\n\n**If not using a TTY stream for input, use the [`'line'`](#event-line) event.**\n\nOne possible use case would be as follows:\n\n```js\nconst values = ['lorem ipsum', 'dolor sit amet'];\nconst rl = readline.createInterface(process.stdin);\nconst showResults = debounce(() => {\n  console.log(\n    '\\n',\n    values.filter((val) => val.startsWith(rl.line)).join(' '),\n  );\n}, 300);\nprocess.stdin.on('keypress', (c, k) => {\n  showResults();\n});\n```","summary":"The current input data being processed by node.","examples":[{"language":"js","displayName":null,"code":"const values = ['lorem ipsum', 'dolor sit amet'];\nconst rl = readline.createInterface(process.stdin);\nconst showResults = debounce(() => {\n  console.log(\n    '\\n',\n    values.filter((val) => val.startsWith(rl.line)).join(' '),\n  );\n}, 300);\nprocess.stdin.on('keypress', (c, k) => {\n  showResults();\n});"}],"children":[]},{"kind":"property","id":"rlcursor","name":"cursor","title":"`rl.cursor`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.98"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"number | undefined","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6},{"name":"undefined","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#undefined_type","start":9,"end":18}]},"default":null,"description":"The cursor position relative to `rl.line`.\n\nThis will track where the current cursor lands in the input string, when\nreading input from a TTY stream. The position of cursor determines the\nportion of the input string that will be modified as input is processed,\nas well as the column where the terminal caret will be rendered.","summary":"The cursor position relative to `rl.line`.","examples":[],"children":[]},{"kind":"method","id":"rlgetcursorpos","name":"getCursorPos","title":"`rl.getCursorPos()`","scope":"module","overloadOf":null,"stability":null,"added":["v13.5.0","v12.16.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":""}},"description":"Returns the real position of the cursor in relation to the input\nprompt + string. Long input (wrapping) strings, as well as multiple\nline prompts are included in the calculations.","summary":"Returns the real position of the cursor in relation to the input prompt + string. Long input (wrapping) strings, as well as multiple line prompts are included in the calculations.","examples":[],"children":[]}]},{"kind":"section","id":"promises-api","name":"Promises API","title":"Promises API","scope":"module","overloadOf":null,"stability":null,"added":["v17.0.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v24.0.0","v22.17.0"],"prUrl":"https://github.com/nodejs/node/pull/57513","commit":null,"description":"Marking the API stable."}],"description":"","summary":"","examples":[],"children":[{"kind":"class","id":"class-readlinepromisesinterface","name":"Interface","title":"Class: `readlinePromises.Interface`","scope":"module","overloadOf":null,"stability":null,"added":["v17.0.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"extends":{"text":"readline.InterfaceConstructor","links":[{"name":"readline.InterfaceConstructor","href":"readline.html#class-readlineinterfaceconstructor","start":0,"end":29}]},"description":"Instances of the `readlinePromises.Interface` class are constructed using the\n`readlinePromises.createInterface()` method. Every instance is associated with a\nsingle `input` [Readable](stream.html#readable-streams) stream and a single `output` [Writable](stream.html#writable-streams) stream.\nThe `output` stream is used to print prompts for user input that arrives on,\nand is read from, the `input` stream.","summary":"Instances of the `readlinePromises.Interface` class are constructed using the `readlinePromises.createInterface()` method. Every instance is associated with a single `input` Readable stream and a single `output` Writable stream. The `output` stream is used to print prompts for user input that arrives on, and is read from, the `input` stream.","examples":[],"children":[{"kind":"method","id":"rlquestionquery-options","name":"question","title":"`rl.question(query[, options])`","scope":"module","overloadOf":null,"stability":null,"added":["v17.0.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"query","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"A statement or query to write to `output`, prepended to the\nprompt.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[{"name":"signal","type":{"text":"AbortSignal","links":[{"name":"AbortSignal","href":"globals.html#class-abortsignal","start":0,"end":11}]},"description":"Optionally allows the `question()` to be canceled\nusing an `AbortSignal`.","default":null,"optional":false,"rest":false,"properties":[]}]}],"returns":{"type":{"text":"Promise","links":[{"name":"Promise","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise","start":0,"end":7}]},"description":"A promise that is fulfilled with the user's\ninput in response to the `query`."}},"description":"The `rl.question()` method displays the `query` by writing it to the `output`,\nwaits for user input to be provided on `input`, then invokes the `callback`\nfunction passing the provided input as the first argument.\n\nWhen called, `rl.question()` will resume the `input` stream if it has been\npaused.\n\nIf the `readlinePromises.Interface` was created with `output` set to `null` or\n`undefined` the `query` is not written.\n\nIf the question is called after `rl.close()`, it returns a rejected promise.\n\nExample usage:\n\n```mjs\nconst answer = await rl.question('What is your favorite food? ');\nconsole.log(`Oh, so your favorite food is ${answer}`);\n```\n\nUsing an `AbortSignal` to cancel a question.\n\n```mjs\nconst signal = AbortSignal.timeout(10_000);\n\nsignal.addEventListener('abort', () => {\n  console.log('The food question timed out');\n}, { once: true });\n\nconst answer = await rl.question('What is your favorite food? ', { signal });\nconsole.log(`Oh, so your favorite food is ${answer}`);\n```","summary":"The `rl.question()` method displays the `query` by writing it to the `output`, waits for user input to be provided on `input`, then invokes the `callback` function passing the provided input as the first argument.","examples":[{"language":"mjs","displayName":null,"code":"const answer = await rl.question('What is your favorite food? ');\nconsole.log(`Oh, so your favorite food is ${answer}`);"},{"language":"mjs","displayName":null,"code":"const signal = AbortSignal.timeout(10_000);\n\nsignal.addEventListener('abort', () => {\n  console.log('The food question timed out');\n}, { once: true });\n\nconst answer = await rl.question('What is your favorite food? ', { signal });\nconsole.log(`Oh, so your favorite food is ${answer}`);"}],"children":[]}]},{"kind":"class","id":"class-readlinepromisesreadline","name":"Readline","title":"Class: `readlinePromises.Readline`","scope":"module","overloadOf":null,"stability":null,"added":["v17.0.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"extends":null,"description":"","summary":"","examples":[],"children":[{"kind":"constructor","id":"new-readlinepromisesreadlinestream-options","name":"Readline","title":"`new readlinePromises.Readline(stream[, options])`","scope":"module","overloadOf":null,"stability":null,"added":["v17.0.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"stream","type":{"text":"stream.Writable","links":[{"name":"stream.Writable","href":"stream.html#class-streamwritable","start":0,"end":15}]},"description":"A [TTY](tty.html) stream.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[{"name":"autoCommit","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"If `true`, no need to call `rl.commit()`.","default":null,"optional":false,"rest":false,"properties":[]}]}],"returns":null},"description":"","summary":"","examples":[],"children":[]},{"kind":"method","id":"rlclearlinedir","name":"clearLine","title":"`rl.clearLine(dir)`","scope":"module","overloadOf":null,"stability":null,"added":["v17.0.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"dir","type":{"text":"integer","links":[{"name":"integer","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":7}]},"description":"","default":null,"optional":false,"rest":false,"properties":[{"name":"-1","type":null,"description":"to the left from cursor","default":null,"optional":false,"rest":false,"properties":[]},{"name":"1","type":null,"description":"to the right from cursor","default":null,"optional":false,"rest":false,"properties":[]},{"name":"0","type":null,"description":"the entire line","default":null,"optional":false,"rest":false,"properties":[]}]}],"returns":{"type":null,"description":"this"}},"description":"The `rl.clearLine()` method adds to the internal list of pending action an\naction that clears current line of the associated `stream` in a specified\ndirection identified by `dir`.\nCall `rl.commit()` to see the effect of this method, unless `autoCommit: true`\nwas passed to the constructor.","summary":"The `rl.clearLine()` method adds to the internal list of pending action an action that clears current line of the associated `stream` in a specified direction identified by `dir`. Call `rl.commit()` to see the effect of this method, unless `autoCommit: true` was passed to the constructor.","examples":[],"children":[]},{"kind":"method","id":"rlclearscreendown","name":"clearScreenDown","title":"`rl.clearScreenDown()`","scope":"module","overloadOf":null,"stability":null,"added":["v17.0.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":null,"description":"this"}},"description":"The `rl.clearScreenDown()` method adds to the internal list of pending action an\naction that clears the associated stream from the current position of the\ncursor down.\nCall `rl.commit()` to see the effect of this method, unless `autoCommit: true`\nwas passed to the constructor.","summary":"The `rl.clearScreenDown()` method adds to the internal list of pending action an action that clears the associated stream from the current position of the cursor down. Call `rl.commit()` to see the effect of this method, unless `autoCommit: true` was passed to the constructor.","examples":[],"children":[]},{"kind":"method","id":"rlcommit","name":"commit","title":"`rl.commit()`","scope":"module","overloadOf":null,"stability":null,"added":["v17.0.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":{"text":"Promise","links":[{"name":"Promise","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise","start":0,"end":7}]},"description":""}},"description":"The `rl.commit()` method sends all the pending actions to the associated\n`stream` and clears the internal list of pending actions.","summary":"The `rl.commit()` method sends all the pending actions to the associated `stream` and clears the internal list of pending actions.","examples":[],"children":[]},{"kind":"method","id":"rlcursortox-y","name":"cursorTo","title":"`rl.cursorTo(x[, y])`","scope":"module","overloadOf":null,"stability":null,"added":["v17.0.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"x","type":{"text":"integer","links":[{"name":"integer","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":7}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"y","type":{"text":"integer","links":[{"name":"integer","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":7}]},"description":"","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":null,"description":"this"}},"description":"The `rl.cursorTo()` method adds to the internal list of pending action an action\nthat moves cursor to the specified position in the associated `stream`.\nCall `rl.commit()` to see the effect of this method, unless `autoCommit: true`\nwas passed to the constructor.","summary":"The `rl.cursorTo()` method adds to the internal list of pending action an action that moves cursor to the specified position in the associated `stream`. Call `rl.commit()` to see the effect of this method, unless `autoCommit: true` was passed to the constructor.","examples":[],"children":[]},{"kind":"method","id":"rlmovecursordx-dy","name":"moveCursor","title":"`rl.moveCursor(dx, dy)`","scope":"module","overloadOf":null,"stability":null,"added":["v17.0.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"dx","type":{"text":"integer","links":[{"name":"integer","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":7}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"dy","type":{"text":"integer","links":[{"name":"integer","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":7}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"returns":{"type":null,"description":"this"}},"description":"The `rl.moveCursor()` method adds to the internal list of pending action an\naction that moves the cursor *relative* to its current position in the\nassociated `stream`.\nCall `rl.commit()` to see the effect of this method, unless `autoCommit: true`\nwas passed to the constructor.","summary":"The `rl.moveCursor()` method adds to the internal list of pending action an action that moves the cursor _relative_ to its current position in the associated `stream`. Call `rl.commit()` to see the effect of this method, unless `autoCommit: true` was passed to the constructor.","examples":[],"children":[]},{"kind":"method","id":"rlrollback","name":"rollback","title":"`rl.rollback()`","scope":"module","overloadOf":null,"stability":null,"added":["v17.0.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":null,"description":"this"}},"description":"The `rl.rollback` methods clears the internal list of pending actions without\nsending it to the associated `stream`.","summary":"The `rl.rollback` methods clears the internal list of pending actions without sending it to the associated `stream`.","examples":[],"children":[]}]},{"kind":"method","id":"readlinepromisescreateinterfaceoptions","name":"createInterface","title":"`readlinePromises.createInterface(options)`","scope":"module","overloadOf":null,"stability":null,"added":["v17.0.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[{"name":"input","type":{"text":"stream.Readable","links":[{"name":"stream.Readable","href":"stream.html#class-streamreadable","start":0,"end":15}]},"description":"The [Readable](stream.html#readable-streams) stream to listen to. This option\nis *required*.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"output","type":{"text":"stream.Writable","links":[{"name":"stream.Writable","href":"stream.html#class-streamwritable","start":0,"end":15}]},"description":"The [Writable](stream.html#writable-streams) stream to write readline data\nto.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"completer","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"An optional function used for Tab autocompletion.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"terminal","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"`true` if the `input` and `output` streams should be\ntreated like a TTY, and have ANSI/VT100 escape codes written to it.","default":"checking `isTTY` on the `output` stream upon instantiation","optional":true,"rest":false,"properties":[]},{"name":"history","type":{"text":"string[]","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Initial list of history lines. This option makes sense\nonly if `terminal` is set to `true` by the user or by an internal `output`\ncheck, otherwise the history caching mechanism is not initialized at all.","default":"[]","optional":true,"rest":false,"properties":[]},{"name":"historySize","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"Maximum number of history lines retained. To disable\nthe history set this value to `0`. This option makes sense only if\n`terminal` is set to `true` by the user or by an internal `output` check,\notherwise the history caching mechanism is not initialized at all.","default":"30","optional":true,"rest":false,"properties":[]},{"name":"removeHistoryDuplicates","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"If `true`, when a new input line added\nto the history list duplicates an older one, this removes the older line\nfrom the list.","default":"false","optional":true,"rest":false,"properties":[]},{"name":"prompt","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"The prompt string to use.","default":"'> '","optional":true,"rest":false,"properties":[]},{"name":"crlfDelay","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"If the delay between `\\r` and `\\n` exceeds\n`crlfDelay` milliseconds, both `\\r` and `\\n` will be treated as separate\nend-of-line input. `crlfDelay` will be coerced to a number no less than\n`100`. It can be set to `Infinity`, in which case `\\r` followed by `\\n`\nwill always be considered a single newline (which may be reasonable for\n[reading files](#example-read-file-stream-line-by-line) with `\\r\\n` line delimiter).","default":"100","optional":true,"rest":false,"properties":[]},{"name":"escapeCodeTimeout","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"The duration `readlinePromises` will wait for a\ncharacter (when reading an ambiguous key sequence in milliseconds one that\ncan both form a complete key sequence using the input read so far and can\ntake additional input to complete a longer key sequence).","default":"500","optional":true,"rest":false,"properties":[]},{"name":"tabSize","type":{"text":"integer","links":[{"name":"integer","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":7}]},"description":"The number of spaces a tab is equal to (minimum 1).","default":"8","optional":true,"rest":false,"properties":[]},{"name":"signal","type":{"text":"AbortSignal","links":[{"name":"AbortSignal","href":"globals.html#class-abortsignal","start":0,"end":11}]},"description":"Allows closing the interface using an AbortSignal.","default":null,"optional":false,"rest":false,"properties":[]}]}],"returns":{"type":{"text":"readlinePromises.Interface","links":[{"name":"readlinePromises.Interface","href":"readline.html#class-readlinepromisesinterface","start":0,"end":26}]},"description":""}},"description":"The `readlinePromises.createInterface()` method creates a new `readlinePromises.Interface`\ninstance.\n\n```mjs\nimport { createInterface } from 'node:readline/promises';\nimport { stdin, stdout } from 'node:process';\nconst rl = createInterface({\n  input: stdin,\n  output: stdout,\n});\n```\n\n```cjs\nconst { createInterface } = require('node:readline/promises');\nconst rl = createInterface({\n  input: process.stdin,\n  output: process.stdout,\n});\n```\n\nOnce the `readlinePromises.Interface` instance is created, the most common case\nis to listen for the `'line'` event:\n\n```js\nrl.on('line', (line) => {\n  console.log(`Received: ${line}`);\n});\n```\n\nIf `terminal` is `true` for this instance then the `output` stream will get\nthe best compatibility if it defines an `output.columns` property and emits\na `'resize'` event on the `output` if or when the columns ever change\n([`process.stdout`](process.html#processstdout) does this automatically when it is a TTY).","summary":"The `readlinePromises.createInterface()` method creates a new `readlinePromises.Interface` instance.","examples":[{"language":"mjs","displayName":null,"code":"import { createInterface } from 'node:readline/promises';\nimport { stdin, stdout } from 'node:process';\nconst rl = createInterface({\n  input: stdin,\n  output: stdout,\n});"},{"language":"cjs","displayName":null,"code":"const { createInterface } = require('node:readline/promises');\nconst rl = createInterface({\n  input: process.stdin,\n  output: process.stdout,\n});"},{"language":"js","displayName":null,"code":"rl.on('line', (line) => {\n  console.log(`Received: ${line}`);\n});"}],"children":[{"kind":"section","id":"use-of-the-completer-function","name":"Use of the completer function","title":"Use of the `completer` function","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"The `completer` function takes the current line entered by the user\nas an argument, and returns an `Array` with 2 entries:\n\n* An `Array` with matching entries for the completion.\n* The substring that was used for the matching.\n\nFor instance: `[[substr1, substr2, ...], originalsubstring]`.\n\n```js\nfunction completer(line) {\n  const completions = '.help .error .exit .quit .q'.split(' ');\n  const hits = completions.filter((c) => c.startsWith(line));\n  // Show all completions if none found\n  return [hits.length ? hits : completions, line];\n}\n```\n\nThe `completer` function can also return a {Promise}, or be asynchronous:\n\n```js\nasync function completer(linePartial) {\n  await someAsyncWork();\n  return [['123'], linePartial];\n}\n```","summary":"The `completer` function takes the current line entered by the user as an argument, and returns an `Array` with 2 entries:","examples":[{"language":"js","displayName":null,"code":"function completer(line) {\n  const completions = '.help .error .exit .quit .q'.split(' ');\n  const hits = completions.filter((c) => c.startsWith(line));\n  // Show all completions if none found\n  return [hits.length ? hits : completions, line];\n}"},{"language":"js","displayName":null,"code":"async function completer(linePartial) {\n  await someAsyncWork();\n  return [['123'], linePartial];\n}"}],"children":[]}]}]},{"kind":"section","id":"callback-api","name":"Callback API","title":"Callback API","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.104"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"","summary":"","examples":[],"children":[{"kind":"class","id":"class-readlineinterface","name":"Interface","title":"Class: `readline.Interface`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.104"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v17.0.0"],"prUrl":"https://github.com/nodejs/node/pull/37947","commit":null,"description":"The class `readline.Interface` now inherits from `Interface`."}],"extends":{"text":"readline.InterfaceConstructor","links":[{"name":"readline.InterfaceConstructor","href":"readline.html#class-readlineinterfaceconstructor","start":0,"end":29}]},"description":"Instances of the `readline.Interface` class are constructed using the\n`readline.createInterface()` method. Every instance is associated with a\nsingle `input` [Readable](stream.html#readable-streams) stream and a single `output` [Writable](stream.html#writable-streams) stream.\nThe `output` stream is used to print prompts for user input that arrives on,\nand is read from, the `input` stream.","summary":"Instances of the `readline.Interface` class are constructed using the `readline.createInterface()` method. Every instance is associated with a single `input` Readable stream and a single `output` Writable stream. The `output` stream is used to print prompts for user input that arrives on, and is read from, the `input` stream.","examples":[],"children":[{"kind":"method","id":"rlquestionquery-options-callback","name":"question","title":"`rl.question(query[, options], callback)`","scope":"module","overloadOf":null,"stability":null,"added":["v0.3.3"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"query","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"A statement or query to write to `output`, prepended to the\nprompt.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[{"name":"signal","type":{"text":"AbortSignal","links":[{"name":"AbortSignal","href":"globals.html#class-abortsignal","start":0,"end":11}]},"description":"Optionally allows the `question()` to be canceled\nusing an `AbortController`.","default":null,"optional":false,"rest":false,"properties":[]}]},{"name":"callback","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"A callback function that is invoked with the user's\ninput in response to the `query`.","default":null,"optional":false,"rest":false,"properties":[]}],"returns":null},"description":"The `rl.question()` method displays the `query` by writing it to the `output`,\nwaits for user input to be provided on `input`, then invokes the `callback`\nfunction passing the provided input as the first argument.\n\nWhen called, `rl.question()` will resume the `input` stream if it has been\npaused.\n\nIf the `readline.Interface` was created with `output` set to `null` or\n`undefined` the `query` is not written.\n\nThe `callback` function passed to `rl.question()` does not follow the typical\npattern of accepting an `Error` object or `null` as the first argument.\nThe `callback` is called with the provided answer as the only argument.\n\nAn error will be thrown if calling `rl.question()` after `rl.close()`.\n\nExample usage:\n\n```js\nrl.question('What is your favorite food? ', (answer) => {\n  console.log(`Oh, so your favorite food is ${answer}`);\n});\n```\n\nUsing an `AbortController` to cancel a question.\n\n```js\nconst ac = new AbortController();\nconst signal = ac.signal;\n\nrl.question('What is your favorite food? ', { signal }, (answer) => {\n  console.log(`Oh, so your favorite food is ${answer}`);\n});\n\nsignal.addEventListener('abort', () => {\n  console.log('The food question timed out');\n}, { once: true });\n\nsetTimeout(() => ac.abort(), 10000);\n```","summary":"The `rl.question()` method displays the `query` by writing it to the `output`, waits for user input to be provided on `input`, then invokes the `callback` function passing the provided input as the first argument.","examples":[{"language":"js","displayName":null,"code":"rl.question('What is your favorite food? ', (answer) => {\n  console.log(`Oh, so your favorite food is ${answer}`);\n});"},{"language":"js","displayName":null,"code":"const ac = new AbortController();\nconst signal = ac.signal;\n\nrl.question('What is your favorite food? ', { signal }, (answer) => {\n  console.log(`Oh, so your favorite food is ${answer}`);\n});\n\nsignal.addEventListener('abort', () => {\n  console.log('The food question timed out');\n}, { once: true });\n\nsetTimeout(() => ac.abort(), 10000);"}],"children":[]}]},{"kind":"method","id":"readlineclearlinestream-dir-callback","name":"clearLine","title":"`readline.clearLine(stream, dir[, callback])`","scope":"module","overloadOf":null,"stability":null,"added":["v0.7.7"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v18.0.0"],"prUrl":"https://github.com/nodejs/node/pull/41678","commit":null,"description":"Passing an invalid callback to the `callback` argument now throws `ERR_INVALID_ARG_TYPE` instead of `ERR_INVALID_CALLBACK`."},{"versions":["v12.7.0"],"prUrl":"https://github.com/nodejs/node/pull/28674","commit":null,"description":"The stream's write() callback and return value are exposed."}],"signature":{"parameters":[{"name":"stream","type":{"text":"stream.Writable","links":[{"name":"stream.Writable","href":"stream.html#class-streamwritable","start":0,"end":15}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"dir","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[{"name":"-1","type":null,"description":"to the left from cursor","default":null,"optional":false,"rest":false,"properties":[]},{"name":"1","type":null,"description":"to the right from cursor","default":null,"optional":false,"rest":false,"properties":[]},{"name":"0","type":null,"description":"the entire line","default":null,"optional":false,"rest":false,"properties":[]}]},{"name":"callback","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"Invoked once the operation completes.","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"`false` if `stream` wishes for the calling code to wait for\nthe `'drain'` event to be emitted before continuing to write additional data;\notherwise `true`."}},"description":"The `readline.clearLine()` method clears current line of given [TTY](tty.html) stream\nin a specified direction identified by `dir`.","summary":"The `readline.clearLine()` method clears current line of given TTY stream in a specified direction identified by `dir`.","examples":[],"children":[]},{"kind":"method","id":"readlineclearscreendownstream-callback","name":"clearScreenDown","title":"`readline.clearScreenDown(stream[, callback])`","scope":"module","overloadOf":null,"stability":null,"added":["v0.7.7"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v18.0.0"],"prUrl":"https://github.com/nodejs/node/pull/41678","commit":null,"description":"Passing an invalid callback to the `callback` argument now throws `ERR_INVALID_ARG_TYPE` instead of `ERR_INVALID_CALLBACK`."},{"versions":["v12.7.0"],"prUrl":"https://github.com/nodejs/node/pull/28641","commit":null,"description":"The stream's write() callback and return value are exposed."}],"signature":{"parameters":[{"name":"stream","type":{"text":"stream.Writable","links":[{"name":"stream.Writable","href":"stream.html#class-streamwritable","start":0,"end":15}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"callback","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"Invoked once the operation completes.","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"`false` if `stream` wishes for the calling code to wait for\nthe `'drain'` event to be emitted before continuing to write additional data;\notherwise `true`."}},"description":"The `readline.clearScreenDown()` method clears the given [TTY](tty.html) stream from\nthe current position of the cursor down.","summary":"The `readline.clearScreenDown()` method clears the given TTY stream from the current position of the cursor down.","examples":[],"children":[]},{"kind":"method","id":"readlinecreateinterfaceoptions","name":"createInterface","title":"`readline.createInterface(options)`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.98"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v15.14.0","v14.18.0"],"prUrl":"https://github.com/nodejs/node/pull/37932","commit":null,"description":"The `signal` option is supported now."},{"versions":["v15.8.0","v14.18.0"],"prUrl":"https://github.com/nodejs/node/pull/33662","commit":null,"description":"The `history` option is supported now."},{"versions":["v13.9.0"],"prUrl":"https://github.com/nodejs/node/pull/31318","commit":null,"description":"The `tabSize` option is supported now."},{"versions":["v8.3.0","v6.11.4"],"prUrl":"https://github.com/nodejs/node/pull/13497","commit":null,"description":"Remove max limit of `crlfDelay` option."},{"versions":["v6.6.0"],"prUrl":"https://github.com/nodejs/node/pull/8109","commit":null,"description":"The `crlfDelay` option is supported now."},{"versions":["v6.3.0"],"prUrl":"https://github.com/nodejs/node/pull/7125","commit":null,"description":"The `prompt` option is supported now."},{"versions":["v6.0.0"],"prUrl":"https://github.com/nodejs/node/pull/6352","commit":null,"description":"The `historySize` option can be `0` now."}],"signature":{"parameters":[{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[{"name":"input","type":{"text":"stream.Readable","links":[{"name":"stream.Readable","href":"stream.html#class-streamreadable","start":0,"end":15}]},"description":"The [Readable](stream.html#readable-streams) stream to listen to. This option\nis *required*.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"output","type":{"text":"stream.Writable","links":[{"name":"stream.Writable","href":"stream.html#class-streamwritable","start":0,"end":15}]},"description":"The [Writable](stream.html#writable-streams) stream to write readline data\nto.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"completer","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"An optional function used for Tab autocompletion.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"terminal","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"`true` if the `input` and `output` streams should be\ntreated like a TTY, and have ANSI/VT100 escape codes written to it.","default":"checking `isTTY` on the `output` stream upon instantiation","optional":true,"rest":false,"properties":[]},{"name":"history","type":{"text":"string[]","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Initial list of history lines. This option makes sense\nonly if `terminal` is set to `true` by the user or by an internal `output`\ncheck, otherwise the history caching mechanism is not initialized at all.","default":"[]","optional":true,"rest":false,"properties":[]},{"name":"historySize","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"Maximum number of history lines retained. To disable\nthe history set this value to `0`. This option makes sense only if\n`terminal` is set to `true` by the user or by an internal `output` check,\notherwise the history caching mechanism is not initialized at all.","default":"30","optional":true,"rest":false,"properties":[]},{"name":"removeHistoryDuplicates","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"If `true`, when a new input line added\nto the history list duplicates an older one, this removes the older line\nfrom the list.","default":"false","optional":true,"rest":false,"properties":[]},{"name":"prompt","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"The prompt string to use.","default":"'> '","optional":true,"rest":false,"properties":[]},{"name":"crlfDelay","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"If the delay between `\\r` and `\\n` exceeds\n`crlfDelay` milliseconds, both `\\r` and `\\n` will be treated as separate\nend-of-line input. `crlfDelay` will be coerced to a number no less than\n`100`. It can be set to `Infinity`, in which case `\\r` followed by `\\n`\nwill always be considered a single newline (which may be reasonable for\n[reading files](#example-read-file-stream-line-by-line) with `\\r\\n` line delimiter).","default":"100","optional":true,"rest":false,"properties":[]},{"name":"escapeCodeTimeout","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"The duration `readline` will wait for a\ncharacter (when reading an ambiguous key sequence in milliseconds one that\ncan both form a complete key sequence using the input read so far and can\ntake additional input to complete a longer key sequence).","default":"500","optional":true,"rest":false,"properties":[]},{"name":"tabSize","type":{"text":"integer","links":[{"name":"integer","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":7}]},"description":"The number of spaces a tab is equal to (minimum 1).","default":"8","optional":true,"rest":false,"properties":[]},{"name":"signal","type":{"text":"AbortSignal","links":[{"name":"AbortSignal","href":"globals.html#class-abortsignal","start":0,"end":11}]},"description":"Allows closing the interface using an AbortSignal.\nAborting the signal will internally call `close` on the interface.","default":null,"optional":false,"rest":false,"properties":[]}]}],"returns":{"type":{"text":"readline.Interface","links":[{"name":"readline.Interface","href":"readline.html#class-readlineinterface","start":0,"end":18}]},"description":""}},"description":"The `readline.createInterface()` method creates a new `readline.Interface`\ninstance.\n\n```mjs\nimport { createInterface } from 'node:readline';\nimport { stdin, stdout } from 'node:process';\nconst rl = createInterface({\n  input: stdin,\n  output: stdout,\n});\n```\n\n```cjs\nconst { createInterface } = require('node:readline');\nconst rl = createInterface({\n  input: process.stdin,\n  output: process.stdout,\n});\n```\n\nOnce the `readline.Interface` instance is created, the most common case is to\nlisten for the `'line'` event:\n\n```js\nrl.on('line', (line) => {\n  console.log(`Received: ${line}`);\n});\n```\n\nIf `terminal` is `true` for this instance then the `output` stream will get\nthe best compatibility if it defines an `output.columns` property and emits\na `'resize'` event on the `output` if or when the columns ever change\n([`process.stdout`](process.html#processstdout) does this automatically when it is a TTY).\n\nWhen creating a `readline.Interface` using `stdin` as input, the program\nwill not terminate until it receives an [EOF character](https://en.wikipedia.org/wiki/End-of-file#EOF_character). To exit without\nwaiting for user input, call `process.stdin.unref()`.","summary":"The `readline.createInterface()` method creates a new `readline.Interface` instance.","examples":[{"language":"mjs","displayName":null,"code":"import { createInterface } from 'node:readline';\nimport { stdin, stdout } from 'node:process';\nconst rl = createInterface({\n  input: stdin,\n  output: stdout,\n});"},{"language":"cjs","displayName":null,"code":"const { createInterface } = require('node:readline');\nconst rl = createInterface({\n  input: process.stdin,\n  output: process.stdout,\n});"},{"language":"js","displayName":null,"code":"rl.on('line', (line) => {\n  console.log(`Received: ${line}`);\n});"}],"children":[{"kind":"section","id":"use-of-the-completer-function-1","name":"Use of the completer function","title":"Use of the `completer` function","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"The `completer` function takes the current line entered by the user\nas an argument, and returns an `Array` with 2 entries:\n\n* An `Array` with matching entries for the completion.\n* The substring that was used for the matching.\n\nFor instance: `[[substr1, substr2, ...], originalsubstring]`.\n\n```js\nfunction completer(line) {\n  const completions = '.help .error .exit .quit .q'.split(' ');\n  const hits = completions.filter((c) => c.startsWith(line));\n  // Show all completions if none found\n  return [hits.length ? hits : completions, line];\n}\n```\n\nThe `completer` function can be called asynchronously if it accepts two\narguments:\n\n```js\nfunction completer(linePartial, callback) {\n  callback(null, [['123'], linePartial]);\n}\n```","summary":"The `completer` function takes the current line entered by the user as an argument, and returns an `Array` with 2 entries:","examples":[{"language":"js","displayName":null,"code":"function completer(line) {\n  const completions = '.help .error .exit .quit .q'.split(' ');\n  const hits = completions.filter((c) => c.startsWith(line));\n  // Show all completions if none found\n  return [hits.length ? hits : completions, line];\n}"},{"language":"js","displayName":null,"code":"function completer(linePartial, callback) {\n  callback(null, [['123'], linePartial]);\n}"}],"children":[]}]},{"kind":"method","id":"readlinecursortostream-x-y-callback","name":"cursorTo","title":"`readline.cursorTo(stream, x[, y][, callback])`","scope":"module","overloadOf":null,"stability":null,"added":["v0.7.7"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v18.0.0"],"prUrl":"https://github.com/nodejs/node/pull/41678","commit":null,"description":"Passing an invalid callback to the `callback` argument now throws `ERR_INVALID_ARG_TYPE` instead of `ERR_INVALID_CALLBACK`."},{"versions":["v12.7.0"],"prUrl":"https://github.com/nodejs/node/pull/28674","commit":null,"description":"The stream's write() callback and return value are exposed."}],"signature":{"parameters":[{"name":"stream","type":{"text":"stream.Writable","links":[{"name":"stream.Writable","href":"stream.html#class-streamwritable","start":0,"end":15}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"x","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"y","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[]},{"name":"callback","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"Invoked once the operation completes.","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"`false` if `stream` wishes for the calling code to wait for\nthe `'drain'` event to be emitted before continuing to write additional data;\notherwise `true`."}},"description":"The `readline.cursorTo()` method moves cursor to the specified position in a\ngiven [TTY](tty.html) `stream`.","summary":"The `readline.cursorTo()` method moves cursor to the specified position in a given TTY `stream`.","examples":[],"children":[]},{"kind":"method","id":"readlinemovecursorstream-dx-dy-callback","name":"moveCursor","title":"`readline.moveCursor(stream, dx, dy[, callback])`","scope":"module","overloadOf":null,"stability":null,"added":["v0.7.7"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v18.0.0"],"prUrl":"https://github.com/nodejs/node/pull/41678","commit":null,"description":"Passing an invalid callback to the `callback` argument now throws `ERR_INVALID_ARG_TYPE` instead of `ERR_INVALID_CALLBACK`."},{"versions":["v12.7.0"],"prUrl":"https://github.com/nodejs/node/pull/28674","commit":null,"description":"The stream's write() callback and return value are exposed."}],"signature":{"parameters":[{"name":"stream","type":{"text":"stream.Writable","links":[{"name":"stream.Writable","href":"stream.html#class-streamwritable","start":0,"end":15}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"dx","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"dy","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"callback","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"Invoked once the operation completes.","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"`false` if `stream` wishes for the calling code to wait for\nthe `'drain'` event to be emitted before continuing to write additional data;\notherwise `true`."}},"description":"The `readline.moveCursor()` method moves the cursor *relative* to its current\nposition in a given [TTY](tty.html) `stream`.","summary":"The `readline.moveCursor()` method moves the cursor _relative_ to its current position in a given TTY `stream`.","examples":[],"children":[]}]},{"kind":"method","id":"readlineemitkeypresseventsstream-interface","name":"emitKeypressEvents","title":"`readline.emitKeypressEvents(stream[, interface])`","scope":"module","overloadOf":null,"stability":null,"added":["v0.7.7"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"stream","type":{"text":"stream.Readable","links":[{"name":"stream.Readable","href":"stream.html#class-streamreadable","start":0,"end":15}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"interface","type":{"text":"readline.InterfaceConstructor","links":[{"name":"readline.InterfaceConstructor","href":"readline.html#class-readlineinterfaceconstructor","start":0,"end":29}]},"description":"","default":null,"optional":true,"rest":false,"properties":[]}],"returns":null},"description":"The `readline.emitKeypressEvents()` method causes the given [Readable](stream.html#readable-streams)\nstream to begin emitting `'keypress'` events corresponding to received input.\n\nOptionally, `interface` specifies a `readline.Interface` instance for which\nautocompletion is disabled when copy-pasted input is detected.\n\nIf the `stream` is a [TTY](tty.html), then it must be in raw mode.\n\nThis is automatically called by any readline instance on its `input` if the\n`input` is a terminal. Closing the `readline` instance does not stop\nthe `input` from emitting `'keypress'` events.\n\n```js\nreadline.emitKeypressEvents(process.stdin);\nif (process.stdin.isTTY)\n  process.stdin.setRawMode(true);\n```","summary":"The `readline.emitKeypressEvents()` method causes the given Readable stream to begin emitting `'keypress'` events corresponding to received input.","examples":[{"language":"js","displayName":null,"code":"readline.emitKeypressEvents(process.stdin);\nif (process.stdin.isTTY)\n  process.stdin.setRawMode(true);"}],"children":[]},{"kind":"section","id":"example-tiny-cli","name":"Example: Tiny CLI","title":"Example: Tiny CLI","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"The following example illustrates the use of `readline.Interface` class to\nimplement a small command-line interface:\n\n```mjs\nimport { createInterface } from 'node:readline';\nimport { exit, stdin, stdout } from 'node:process';\nconst rl = createInterface({\n  input: stdin,\n  output: stdout,\n  prompt: 'OHAI> ',\n});\n\nrl.prompt();\n\nrl.on('line', (line) => {\n  switch (line.trim()) {\n    case 'hello':\n      console.log('world!');\n      break;\n    default:\n      console.log(`Say what? I might have heard '${line.trim()}'`);\n      break;\n  }\n  rl.prompt();\n}).on('close', () => {\n  console.log('Have a great day!');\n  exit(0);\n});\n```\n\n```cjs\nconst { createInterface } = require('node:readline');\nconst rl = createInterface({\n  input: process.stdin,\n  output: process.stdout,\n  prompt: 'OHAI> ',\n});\n\nrl.prompt();\n\nrl.on('line', (line) => {\n  switch (line.trim()) {\n    case 'hello':\n      console.log('world!');\n      break;\n    default:\n      console.log(`Say what? I might have heard '${line.trim()}'`);\n      break;\n  }\n  rl.prompt();\n}).on('close', () => {\n  console.log('Have a great day!');\n  process.exit(0);\n});\n```","summary":"The following example illustrates the use of `readline.Interface` class to implement a small command-line interface:","examples":[{"language":"mjs","displayName":null,"code":"import { createInterface } from 'node:readline';\nimport { exit, stdin, stdout } from 'node:process';\nconst rl = createInterface({\n  input: stdin,\n  output: stdout,\n  prompt: 'OHAI> ',\n});\n\nrl.prompt();\n\nrl.on('line', (line) => {\n  switch (line.trim()) {\n    case 'hello':\n      console.log('world!');\n      break;\n    default:\n      console.log(`Say what? I might have heard '${line.trim()}'`);\n      break;\n  }\n  rl.prompt();\n}).on('close', () => {\n  console.log('Have a great day!');\n  exit(0);\n});"},{"language":"cjs","displayName":null,"code":"const { createInterface } = require('node:readline');\nconst rl = createInterface({\n  input: process.stdin,\n  output: process.stdout,\n  prompt: 'OHAI> ',\n});\n\nrl.prompt();\n\nrl.on('line', (line) => {\n  switch (line.trim()) {\n    case 'hello':\n      console.log('world!');\n      break;\n    default:\n      console.log(`Say what? I might have heard '${line.trim()}'`);\n      break;\n  }\n  rl.prompt();\n}).on('close', () => {\n  console.log('Have a great day!');\n  process.exit(0);\n});"}],"children":[]},{"kind":"section","id":"example-read-file-stream-line-by-line","name":"Example: Read file stream line-by-Line","title":"Example: Read file stream line-by-Line","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"A common use case for `readline` is to consume an input file one line at a\ntime. The easiest way to do so is leveraging the [`fs.ReadStream`](fs.html#class-fsreadstream) API as\nwell as a `for await...of` loop:\n\n```mjs\nimport { createReadStream } from 'node:fs';\nimport { createInterface } from 'node:readline';\n\nasync function processLineByLine() {\n  const fileStream = createReadStream('input.txt');\n\n  const rl = createInterface({\n    input: fileStream,\n    crlfDelay: Infinity,\n  });\n  // Note: we use the crlfDelay option to recognize all instances of CR LF\n  // ('\\r\\n') in input.txt as a single line break.\n\n  for await (const line of rl) {\n    // Each line in input.txt will be successively available here as `line`.\n    console.log(`Line from file: ${line}`);\n  }\n}\n\nprocessLineByLine();\n```\n\n```cjs\nconst { createReadStream } = require('node:fs');\nconst { createInterface } = require('node:readline');\n\nasync function processLineByLine() {\n  const fileStream = createReadStream('input.txt');\n\n  const rl = createInterface({\n    input: fileStream,\n    crlfDelay: Infinity,\n  });\n  // Note: we use the crlfDelay option to recognize all instances of CR LF\n  // ('\\r\\n') in input.txt as a single line break.\n\n  for await (const line of rl) {\n    // Each line in input.txt will be successively available here as `line`.\n    console.log(`Line from file: ${line}`);\n  }\n}\n\nprocessLineByLine();\n```\n\nAlternatively, one could use the [`'line'`](#event-line) event:\n\n```mjs\nimport { createReadStream } from 'node:fs';\nimport { createInterface } from 'node:readline';\n\nconst rl = createInterface({\n  input: createReadStream('sample.txt'),\n  crlfDelay: Infinity,\n});\n\nrl.on('line', (line) => {\n  console.log(`Line from file: ${line}`);\n});\n```\n\n```cjs\nconst { createReadStream } = require('node:fs');\nconst { createInterface } = require('node:readline');\n\nconst rl = createInterface({\n  input: createReadStream('sample.txt'),\n  crlfDelay: Infinity,\n});\n\nrl.on('line', (line) => {\n  console.log(`Line from file: ${line}`);\n});\n```\n\nCurrently, `for await...of` loop can be a bit slower. If `async` / `await`\nflow and speed are both essential, a mixed approach can be applied:\n\n```mjs\nimport { once } from 'node:events';\nimport { createReadStream } from 'node:fs';\nimport { createInterface } from 'node:readline';\n\n(async function processLineByLine() {\n  try {\n    const rl = createInterface({\n      input: createReadStream('big-file.txt'),\n      crlfDelay: Infinity,\n    });\n\n    rl.on('line', (line) => {\n      // Process the line.\n    });\n\n    await once(rl, 'close');\n\n    console.log('File processed.');\n  } catch (err) {\n    console.error(err);\n  }\n})();\n```\n\n```cjs\nconst { once } = require('node:events');\nconst { createReadStream } = require('node:fs');\nconst { createInterface } = require('node:readline');\n\n(async function processLineByLine() {\n  try {\n    const rl = createInterface({\n      input: createReadStream('big-file.txt'),\n      crlfDelay: Infinity,\n    });\n\n    rl.on('line', (line) => {\n      // Process the line.\n    });\n\n    await once(rl, 'close');\n\n    console.log('File processed.');\n  } catch (err) {\n    console.error(err);\n  }\n})();\n```","summary":"A common use case for `readline` is to consume an input file one line at a time. The easiest way to do so is leveraging the `fs.ReadStream` API as well as a `for await...of` loop:","examples":[{"language":"mjs","displayName":null,"code":"import { createReadStream } from 'node:fs';\nimport { createInterface } from 'node:readline';\n\nasync function processLineByLine() {\n  const fileStream = createReadStream('input.txt');\n\n  const rl = createInterface({\n    input: fileStream,\n    crlfDelay: Infinity,\n  });\n  // Note: we use the crlfDelay option to recognize all instances of CR LF\n  // ('\\r\\n') in input.txt as a single line break.\n\n  for await (const line of rl) {\n    // Each line in input.txt will be successively available here as `line`.\n    console.log(`Line from file: ${line}`);\n  }\n}\n\nprocessLineByLine();"},{"language":"cjs","displayName":null,"code":"const { createReadStream } = require('node:fs');\nconst { createInterface } = require('node:readline');\n\nasync function processLineByLine() {\n  const fileStream = createReadStream('input.txt');\n\n  const rl = createInterface({\n    input: fileStream,\n    crlfDelay: Infinity,\n  });\n  // Note: we use the crlfDelay option to recognize all instances of CR LF\n  // ('\\r\\n') in input.txt as a single line break.\n\n  for await (const line of rl) {\n    // Each line in input.txt will be successively available here as `line`.\n    console.log(`Line from file: ${line}`);\n  }\n}\n\nprocessLineByLine();"},{"language":"mjs","displayName":null,"code":"import { createReadStream } from 'node:fs';\nimport { createInterface } from 'node:readline';\n\nconst rl = createInterface({\n  input: createReadStream('sample.txt'),\n  crlfDelay: Infinity,\n});\n\nrl.on('line', (line) => {\n  console.log(`Line from file: ${line}`);\n});"},{"language":"cjs","displayName":null,"code":"const { createReadStream } = require('node:fs');\nconst { createInterface } = require('node:readline');\n\nconst rl = createInterface({\n  input: createReadStream('sample.txt'),\n  crlfDelay: Infinity,\n});\n\nrl.on('line', (line) => {\n  console.log(`Line from file: ${line}`);\n});"},{"language":"mjs","displayName":null,"code":"import { once } from 'node:events';\nimport { createReadStream } from 'node:fs';\nimport { createInterface } from 'node:readline';\n\n(async function processLineByLine() {\n  try {\n    const rl = createInterface({\n      input: createReadStream('big-file.txt'),\n      crlfDelay: Infinity,\n    });\n\n    rl.on('line', (line) => {\n      // Process the line.\n    });\n\n    await once(rl, 'close');\n\n    console.log('File processed.');\n  } catch (err) {\n    console.error(err);\n  }\n})();"},{"language":"cjs","displayName":null,"code":"const { once } = require('node:events');\nconst { createReadStream } = require('node:fs');\nconst { createInterface } = require('node:readline');\n\n(async function processLineByLine() {\n  try {\n    const rl = createInterface({\n      input: createReadStream('big-file.txt'),\n      crlfDelay: Infinity,\n    });\n\n    rl.on('line', (line) => {\n      // Process the line.\n    });\n\n    await once(rl, 'close');\n\n    console.log('File processed.');\n  } catch (err) {\n    console.error(err);\n  }\n})();"}],"children":[]},{"kind":"section","id":"tty-keybindings","name":"TTY keybindings","title":"TTY keybindings","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"<table>\n  <tr>\n    <th>Keybindings</th>\n    <th>Description</th>\n    <th>Notes</th>\n  </tr>\n  <tr>\n    <td><kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>Backspace</kbd></td>\n    <td>Delete line left</td>\n    <td>Doesn't work on Linux, Mac and Windows</td>\n  </tr>\n  <tr>\n    <td><kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>Delete</kbd></td>\n    <td>Delete line right</td>\n    <td>Doesn't work on Mac</td>\n  </tr>\n  <tr>\n    <td><kbd>Ctrl</kbd>+<kbd>C</kbd></td>\n    <td>Emit <code>SIGINT</code> or close the readline instance</td>\n    <td></td>\n  </tr>\n  <tr>\n    <td><kbd>Ctrl</kbd>+<kbd>H</kbd></td>\n    <td>Delete left</td>\n    <td></td>\n  </tr>\n  <tr>\n    <td><kbd>Ctrl</kbd>+<kbd>D</kbd></td>\n    <td>Delete right or close the readline instance in case the current line is empty / EOF</td>\n    <td>Doesn't work on Windows</td>\n  </tr>\n  <tr>\n    <td><kbd>Ctrl</kbd>+<kbd>U</kbd></td>\n    <td>Delete from the current position to the line start</td>\n    <td></td>\n  </tr>\n  <tr>\n    <td><kbd>Ctrl</kbd>+<kbd>K</kbd></td>\n    <td>Delete from the current position to the end of line</td>\n    <td></td>\n  </tr>\n  <tr>\n    <td><kbd>Ctrl</kbd>+<kbd>Y</kbd></td>\n    <td>Yank (Recall) the previously deleted text</td>\n    <td>Only works with text deleted by <kbd>Ctrl</kbd>+<kbd>U</kbd> or <kbd>Ctrl</kbd>+<kbd>K</kbd></td>\n  </tr>\n  <tr>\n    <td><kbd>Meta</kbd>+<kbd>Y</kbd></td>\n    <td>Cycle among previously deleted texts</td>\n    <td>Only available when the last keystroke is <kbd>Ctrl</kbd>+<kbd>Y</kbd> or <kbd>Meta</kbd>+<kbd>Y</kbd></td>\n  </tr>\n  <tr>\n    <td><kbd>Ctrl</kbd>+<kbd>A</kbd></td>\n    <td>Go to start of line</td>\n    <td></td>\n  </tr>\n  <tr>\n    <td><kbd>Ctrl</kbd>+<kbd>E</kbd></td>\n    <td>Go to end of line</td>\n    <td></td>\n  </tr>\n  <tr>\n    <td><kbd>Ctrl</kbd>+<kbd>B</kbd></td>\n    <td>Back one character</td>\n    <td></td>\n  </tr>\n  <tr>\n    <td><kbd>Ctrl</kbd>+<kbd>F</kbd></td>\n    <td>Forward one character</td>\n    <td></td>\n  </tr>\n  <tr>\n    <td><kbd>Ctrl</kbd>+<kbd>L</kbd></td>\n    <td>Clear screen</td>\n    <td></td>\n  </tr>\n  <tr>\n    <td><kbd>Ctrl</kbd>+<kbd>N</kbd></td>\n    <td>Next history item</td>\n    <td></td>\n  </tr>\n  <tr>\n    <td><kbd>Ctrl</kbd>+<kbd>P</kbd></td>\n    <td>Previous history item</td>\n    <td></td>\n  </tr>\n  <tr>\n    <td><kbd>Ctrl</kbd>+<kbd>-</kbd></td>\n    <td>Undo previous change</td>\n    <td>Any keystroke that emits key code <code>0x1F</code> will do this action.\n    In many terminals, for example <code>xterm</code>,\n    this is bound to <kbd>Ctrl</kbd>+<kbd>-</kbd>.</td>\n  </tr>\n  <tr>\n    <td><kbd>Ctrl</kbd>+<kbd>6</kbd></td>\n    <td>Redo previous change</td>\n    <td>Many terminals don't have a default redo keystroke.\n    We choose key code <code>0x1E</code> to perform redo.\n    In <code>xterm</code>, it is bound to <kbd>Ctrl</kbd>+<kbd>6</kbd>\n    by default.</td>\n  </tr>\n  <tr>\n    <td><kbd>Ctrl</kbd>+<kbd>Z</kbd></td>\n    <td>Moves running process into background. Type\n    <code>fg</code> and press <kbd>Enter</kbd>\n    to return.</td>\n    <td>Doesn't work on Windows</td>\n  </tr>\n  <tr>\n    <td><kbd>Ctrl</kbd>+<kbd>W</kbd> or <kbd>Ctrl</kbd>\n   +<kbd>Backspace</kbd></td>\n    <td>Delete backward to a word boundary</td>\n    <td><kbd>Ctrl</kbd>+<kbd>Backspace</kbd> Doesn't\n    work on Linux, Mac and Windows</td>\n  </tr>\n  <tr>\n    <td><kbd>Ctrl</kbd>+<kbd>Delete</kbd></td>\n    <td>Delete forward to a word boundary</td>\n    <td>Doesn't work on Mac</td>\n  </tr>\n  <tr>\n    <td><kbd>Ctrl</kbd>+<kbd>Left arrow</kbd> or\n    <kbd>Meta</kbd>+<kbd>B</kbd></td>\n    <td>Word left</td>\n    <td><kbd>Ctrl</kbd>+<kbd>Left arrow</kbd> Doesn't work\n    on Mac</td>\n  </tr>\n  <tr>\n    <td><kbd>Ctrl</kbd>+<kbd>Right arrow</kbd> or\n    <kbd>Meta</kbd>+<kbd>F</kbd></td>\n    <td>Word right</td>\n    <td><kbd>Ctrl</kbd>+<kbd>Right arrow</kbd> Doesn't work\n    on Mac</td>\n  </tr>\n  <tr>\n    <td><kbd>Meta</kbd>+<kbd>D</kbd> or <kbd>Meta</kbd>\n   +<kbd>Delete</kbd></td>\n    <td>Delete word right</td>\n    <td><kbd>Meta</kbd>+<kbd>Delete</kbd> Doesn't work\n    on windows</td>\n  </tr>\n  <tr>\n    <td><kbd>Meta</kbd>+<kbd>Backspace</kbd></td>\n    <td>Delete word left</td>\n    <td>Doesn't work on Mac</td>\n  </tr>\n</table>","summary":"","examples":[],"children":[]}]}