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.
npm install readVerified import paths — ran on the pinned version, not inferred.
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.
Upgrade your Node.js version to meet the specified range.
Upgrade your Node.js version to meet the specified range or downgrade `read` to a compatible version.
Update import statements from `const { read } = require('read')` to `import { read } from 'read'`. Ensure your project's `package.json` is configured for ESM (e.g., setting `"type": "module"`) or use appropriate tooling for ESM/CJS interop.Refactor code to use `async/await` or `.then().catch()` with the returned Promise. Remove any `isDefault` checks from the resolved value.
Ensure `read` is used in an interactive terminal environment for `silent` mode to function as intended. For non-interactive scripts, consider if `silent` is appropriate or if alternative input methods are more suitable.
For CommonJS, use named destructuring: `const { read } = require('read')`. For ESM, use named import: `import { read } from 'read'`.Change your import statement from `const { read } = require('read')` to `import { read } from 'read'`.Wrap your `await` call within an `async` function, or use `.then().catch()` with the Promise returned by `read`.