{"library":"read","title":"read - User Input from Stdin","description":"The `read` package provides a utility for securely and flexibly reading user input from `stdin` in Node.js applications. It serves as an enhanced alternative to Node's built-in `readline.question()` method, offering additional features such as silent input (e.g., for passwords), character replacement during silent input, input timeouts, default values, editable default values, terminal forcing, and auto-completion via a `completer` option. As of version 5.0.1, the package is actively maintained by the npm team and targets modern Node.js environments, requiring `^20.17.0 || >=22.9.0`. Major releases (e.g., v2.0.0, v3.0.0, v4.0.0, v5.0.0) typically introduce breaking changes related to Node.js version compatibility or API shifts, with minor releases adding new features like the `history` parameter in v4.1.0. The library primarily uses a Promise-based API for handling input, reflecting modern JavaScript asynchronous patterns.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install read"],"cli":null},"imports":["import { read } from 'read'","import type { ReadOptions } from 'read'"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { read } from 'read';\n\nasync function getUserInput() {\n  try {\n    const username = await read({ prompt: 'Username: ' });\n    console.log(`Hello, ${username}!`);\n\n    const password = await read({\n      prompt: 'Password: ',\n      silent: true,\n      replace: '*',\n      timeout: 15000 // 15 seconds\n    });\n    console.log('Password received (not echoed).');\n\n    const favoriteColor = await read({\n      prompt: 'What is your favorite color? ',\n      default: 'blue',\n      edit: true,\n    });\n    console.log(`Your favorite color is: ${favoriteColor}`);\n\n  } catch (error) {\n    if (error instanceof Error && error.message === 'timed out') {\n      console.error('Input timed out. Please try again.');\n    } else {\n      console.error('An error occurred:', error);\n    }\n    process.exit(1);\n  }\n}\n\ngetUserInput();","lang":"typescript","description":"This example demonstrates prompting for username, a silent password input with timeout and character replacement, and an editable default value for favorite color, using the `read` function and its options.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}