UNPKG

1.26 kBMarkdownView Raw
1For reading user input from stdin.
2
3## USAGE
4
5```javascript
6var read = require("read")
7read(options, callback)
8```
9
10The callback gets called with either the user input, or the default
11specified, or an error, in the traditional `callback(error, result)`
12node style.
13
14## OPTIONS
15
16Every option is optional.
17
18* `prompt` What to write to stdout before reading input.
19* `silent` Don't echo the output as the user types it.
20* `num` Max number of chars to read from terminal.
21* `delim` The char that means we're done. Default: `"\n"`
22* `timeout` Number of ms to wait for user input before giving up.
23* `default` The default value if the user enters nothing.
24
25If silent is true, or num is set, or delim is something other than
26`"\n"`, then read will set raw mode, and read character by character.
27
28At this time, backspace and arrow keys are not supported in raw mode.
29It's probably not too hard to add support for this, perhaps using node's
30built-in readline module.
31
32## CONTRIBUTING
33
34Patches welcome.
35
36## BUGS
37
38In node 0.6.0 through 0.6.5, you must explicitly call
39`process.stdin.destroy()` or `process.exit()` when you know that your
40program is done reading, or else it will keep the event loop running
41forever.
42
43See: <https://github.com/joyent/node/issues/2257>