https://github.com/npm/read
read(1) for node.
https://github.com/npm/read
npm-cli
Last synced: about 1 year ago
JSON representation
read(1) for node.
- Host: GitHub
- URL: https://github.com/npm/read
- Owner: npm
- License: isc
- Created: 2011-12-06T23:23:36.000Z (over 14 years ago)
- Default Branch: main
- Last Pushed: 2025-04-09T21:59:25.000Z (about 1 year ago)
- Last Synced: 2025-05-07T09:50:57.919Z (about 1 year ago)
- Topics: npm-cli
- Language: TypeScript
- Homepage:
- Size: 141 KB
- Stars: 196
- Watchers: 19
- Forks: 34
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
- Security: SECURITY.md
Awesome Lists containing this project
README
## read
For reading user input from stdin.
Similar to the `readline` builtin's `question()` method, but with a
few more features.
## Usage
```javascript
const { read } = require('read')
// or with ESM: import { read } from 'read'
try {
const result = await read(options)
} catch (er) {
console.error(er)
}
```
## Options
Every option is optional.
* `prompt` What to write to stdout before reading input.
* `silent` Don't echo the output as the user types it.
* `replace` Replace silenced characters with the supplied character value.
* `timeout` Number of ms to wait for user input before giving up.
* `default` The default value if the user enters nothing.
* `edit` Allow the user to edit the default value.
* `terminal` Treat the output as a TTY, whether it is or not.
* `input` Readable stream to get input data from. (default `process.stdin`)
* `output` Writable stream to write prompts to. (default: `process.stdout`)
* `completer` Autocomplete callback (see [official api](https://nodejs.org/api/readline.html#readline_readline_createinterface_options) for details
* `history` History array, which will be appended to.
If silent is true, and the input is a TTY, then read will set raw
mode, and read character by character.
## Contributing
Patches welcome.