UNPKG

72 kBMarkdownView Raw
1# readlineSync
2
3[![npm](https://img.shields.io/npm/v/readline-sync.svg)](https://www.npmjs.com/package/readline-sync) [![GitHub issues](https://img.shields.io/github/issues/anseki/readline-sync.svg)](https://github.com/anseki/readline-sync/issues) [![dependencies](https://img.shields.io/badge/dependencies-No%20dependency-brightgreen.svg)](package.json) [![license](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE-MIT)
4
5Synchronous [Readline](http://nodejs.org/api/readline.html) for interactively running to have a conversation with the user via a console(TTY).
6
7readlineSync tries to let your script have a conversation with the user via a console, even when the input/output stream is redirected like `your-script <foo.dat >bar.log`.
8
9<table>
10<tr><td><a href="#basic_options">Basic Options</a></td><td><a href="#utility_methods">Utility Methods</a></td><td><a href="#placeholders">Placeholders</a></td></tr>
11</table>
12
13* Simple case:
14
15```js
16var readlineSync = require('readline-sync');
17
18// Wait for user's response.
19var userName = readlineSync.question('May I have your name? ');
20console.log('Hi ' + userName + '!');
21
22// Handle the secret text (e.g. password).
23var favFood = readlineSync.question('What is your favorite food? ', {
24 hideEchoBack: true // The typed text on screen is hidden by `*` (default).
25});
26console.log('Oh, ' + userName + ' loves ' + favFood + '!');
27```
28
29```console
30May I have your name? CookieMonster
31Hi CookieMonster!
32What is your favorite food? ****
33Oh, CookieMonster loves tofu!
34```
35
36* Get the user's response by a single key without the Enter key:
37
38```js
39var readlineSync = require('readline-sync');
40if (readlineSync.keyInYN('Do you want this module?')) {
41 // 'Y' key was pressed.
42 console.log('Installing now...');
43 // Do something...
44} else {
45 // Another key was pressed.
46 console.log('Searching another...');
47 // Do something...
48}
49```
50
51* Let the user choose an item from a list:
52
53```js
54var readlineSync = require('readline-sync'),
55 animals = ['Lion', 'Elephant', 'Crocodile', 'Giraffe', 'Hippo'],
56 index = readlineSync.keyInSelect(animals, 'Which animal?');
57console.log('Ok, ' + animals[index] + ' goes to your room.');
58```
59
60```console
61[1] Lion
62[2] Elephant
63[3] Crocodile
64[4] Giraffe
65[5] Hippo
66[0] CANCEL
67
68Which animal? [1...5 / 0]: 2
69Ok, Elephant goes to your room.
70```
71
72* An UI like the Range Slider:
73(Press `Z` or `X` key to change a value, and Space Bar to exit)
74
75```js
76var readlineSync = require('readline-sync'),
77 MAX = 60, MIN = 0, value = 30, key;
78console.log('\n\n' + (new Array(20)).join(' ') +
79 '[Z] <- -> [X] FIX: [SPACE]\n');
80while (true) {
81 console.log('\x1B[1A\x1B[K|' +
82 (new Array(value + 1)).join('-') + 'O' +
83 (new Array(MAX - value + 1)).join('-') + '| ' + value);
84 key = readlineSync.keyIn('',
85 {hideEchoBack: true, mask: '', limit: 'zx '});
86 if (key === 'z') { if (value > MIN) { value--; } }
87 else if (key === 'x') { if (value < MAX) { value++; } }
88 else { break; }
89}
90console.log('\nA value the user requested: ' + value);
91```
92
93![sample](screen_03.gif)
94
95* Handle the commands repeatedly, such as the shell interface:
96
97```js
98readlineSync.promptCLLoop({
99 add: function(target, into) {
100 console.log(target + ' is added into ' + into + '.');
101 // Do something...
102 },
103 remove: function(target) {
104 console.log(target + ' is removed.');
105 // Do something...
106 },
107 bye: function() { return true; }
108});
109console.log('Exited');
110```
111
112```console
113> add pic01.png archive
114pic01.png is added into archive.
115> delete pic01.png
116Requested command is not available.
117> remove pic01.png
118pic01.png is removed.
119> bye
120Exited
121```
122
123## <a name="installation"></a>Installation
124
125```console
126npm install readline-sync
127```
128
129## <a name="quick_start"></a>Quick Start
130
131**How does the user input?**
132
133- [Type a reply to a question, and press the Enter key](#quick_start-a) (A)
134- [Type a keyword like a command in prompt, and press the Enter key](#quick_start-b) (B)
135- [Press a single key without the Enter key](#quick_start-c) (C)
136
137<a name="quick_start-a"></a>**(A) What does the user input?**
138
139- [E-mail address](#utility_methods-questionemail)
140- [New password](#utility_methods-questionnewpassword)
141- [Integer number](#utility_methods-questionint)
142- [Floating-point number](#utility_methods-questionfloat)
143- [Local file/directory path](#utility_methods-questionpath)
144- [Others](#basic_methods-question)
145
146<a name="quick_start-b"></a>**(B) What does your script do?**
147
148- [Receive a parsed command-name and arguments](#utility_methods-promptcl)
149- [Receive an input repeatedly](#utility_methods-promptloop)
150- [Receive a parsed command-name and arguments repeatedly](#utility_methods-promptclloop)
151- [Receive an input with prompt that is similar to that of the user's shell](#utility_methods-promptsimshell)
152- [Others](#basic_methods-prompt)
153
154<a name="quick_start-c"></a>**(C) What does the user do?**
155
156- [Say "Yes" or "No"](#utility_methods-keyinyn)
157- [Say "Yes" or "No" explicitly](#utility_methods-keyinynstrict)
158- [Make the running of script continue when ready](#utility_methods-keyinpause)
159- [Choose an item from a list](#utility_methods-keyinselect)
160- [Others](#basic_methods-keyin)
161
162## <a name="basic_methods"></a>Basic Methods
163
164These are used to control details of the behavior. It is recommended to use the [Utility Methods](#utility_methods) instead of Basic Methods if it satisfy your request.
165
166### <a name="basic_methods-question"></a>`question`
167
168```js
169answer = readlineSync.question([query[, options]])
170```
171
172Display a `query` to the user if it's specified, and then return the input from the user after it has been typed and the Enter key was pressed.
173You can specify an `options` (see [Basic Options](#basic_options)) to control the behavior (e.g. refusing unexpected input, avoiding trimming white spaces, etc.). **If you let the user input the secret text (e.g. password), you should consider [`hideEchoBack`](#basic_options-hideechoback) option.**
174
175The `query` may be string, or may not be (e.g. number, Date, Object, etc.). It is converted to string (i.e. `toString` method is called) before it is displayed. (see [Note](#note) also)
176It can include the [placeholders](#placeholders).
177
178For example:
179
180```js
181program = readlineSync.question('Which program starts do you want? ', {
182 defaultInput: 'firefox'
183});
184```
185
186### <a name="basic_methods-prompt"></a>`prompt`
187
188```js
189input = readlineSync.prompt([options])
190```
191
192Display a prompt-sign (see [`prompt`](#basic_options-prompt) option) to the user, and then return the input from the user after it has been typed and the Enter key was pressed.
193You can specify an `options` (see [Basic Options](#basic_options)) to control the behavior (e.g. refusing unexpected input, avoiding trimming white spaces, etc.).
194
195For example:
196
197```js
198while (true) {
199 command = readlineSync.prompt();
200 // Do something...
201}
202```
203
204### <a name="basic_methods-keyin"></a>`keyIn`
205
206```js
207pressedKey = readlineSync.keyIn([query[, options]])
208```
209
210Display a `query` to the user if it's specified, and then return a character as a key immediately it was pressed by the user, **without pressing the Enter key**. Note that the user has no chance to change the input.
211You can specify an `options` (see [Basic Options](#basic_options)) to control the behavior (e.g. ignoring keys except some keys, checking target key, etc.).
212
213The `query` is handled the same as that of the [`question`](#basic_methods-question) method.
214
215For example:
216
217```js
218menuId = readlineSync.keyIn('Hit 1...5 key: ', {limit: '$<1-5>'});
219```
220
221### <a name="basic_methods-setdefaultoptions"></a>`setDefaultOptions`
222
223```js
224currentDefaultOptions = readlineSync.setDefaultOptions([newDefaultOptions])
225```
226
227Change the [Default Options](#basic_options) to the values of properties of `newDefaultOptions` Object.
228All it takes is to specify options that you want change, because unspecified options are not updated.
229
230## <a name="basic_options"></a>Basic Options
231
232[`prompt`](#basic_options-prompt), [`hideEchoBack`](#basic_options-hideechoback), [`mask`](#basic_options-mask), [`limit`](#basic_options-limit), [`limitMessage`](#basic_options-limitmessage), [`defaultInput`](#basic_options-defaultinput), [`trueValue`, `falseValue`](#basic_options-truevalue_falsevalue), [`caseSensitive`](#basic_options-casesensitive), [`keepWhitespace`](#basic_options-keepwhitespace), [`encoding`](#basic_options-encoding), [`bufferSize`](#basic_options-buffersize), [`print`](#basic_options-print), [`history`](#basic_options-history), [`cd`](#basic_options-cd)
233
234An `options` Object can be specified to the methods to control the behavior of readlineSync. The options that were not specified to the methods are got from the Default Options. You can change the Default Options by [`setDefaultOptions`](#basic_methods-setdefaultoptions) method anytime, and it is kept until a current process is exited.
235Specify the options that are often used to the Default Options, and specify temporary options to the methods.
236
237For example:
238
239```js
240readlineSync.setDefaultOptions({limit: ['green', 'yellow', 'red']});
241a1 = readlineSync.question('Which color of signal? '); // Input is limited to 3 things.
242a2 = readlineSync.question('Which color of signal? '); // It's limited yet.
243a3 = readlineSync.question('What is your favorite color? ', {limit: null}); // It's unlimited temporarily.
244a4 = readlineSync.question('Which color of signal? '); // It's limited again.
245readlineSync.setDefaultOptions({limit: ['beef', 'chicken']});
246a5 = readlineSync.question('Beef or Chicken? '); // Input is limited to new 2 things.
247a6 = readlineSync.question('And you? '); // It's limited to 2 things yet.
248```
249
250The Object as `options` can have following properties.
251
252### <a name="basic_options-prompt"></a>`prompt`
253
254_For `prompt*` methods only_
255*Type:* string or others
256*Default:* `'> '`
257
258Set the prompt-sign that is displayed to the user by `prompt*` methods. For example you see `> ` that is Node.js's prompt-sign when you run `node` on the command line.
259This may be string, or may not be (e.g. number, Date, Object, etc.). It is converted to string every time (i.e. `toString` method is called) before it is displayed. (see [Note](#note) also)
260It can include the [placeholders](#placeholders).
261
262For example:
263
264```js
265readlineSync.setDefaultOptions({prompt: '$ '});
266```
267
268```js
269// Display the memory usage always.
270readlineSync.setDefaultOptions({
271 prompt: { // Simple Object that has toString method.
272 toString: function() {
273 var rss = process.memoryUsage().rss;
274 return '[' + (rss > 1024 ? Math.round(rss / 1024) + 'k' : rss) + 'b]$ ';
275 }
276 }
277});
278```
279
280```console
281[13148kb]$ foo
282[13160kb]$ bar
283[13200kb]$
284```
285
286### <a name="basic_options-hideechoback"></a>`hideEchoBack`
287
288*Type:* boolean
289*Default:* `false`
290
291If `true` is specified, hide the secret text (e.g. password) which is typed by user on screen by the mask characters (see [`mask`](#basic_options-mask) option).
292
293For example:
294
295```js
296password = readlineSync.question('PASSWORD: ', {hideEchoBack: true});
297console.log('Login ...');
298```
299
300```console
301PASSWORD: ********
302Login ...
303```
304
305### <a name="basic_options-mask"></a>`mask`
306
307*Type:* string
308*Default:* `'*'`
309
310Set the mask characters that are shown instead of the secret text (e.g. password) when `true` is specified to [`hideEchoBack`](#basic_options-hideechoback) option. If you want to show nothing, specify `''`. (But it might be not user friendly in some cases.)
311**Note:** In some cases (e.g. when the input stream is redirected on Windows XP), `'*'` or `''` might be used whether other one is specified.
312
313For example:
314
315```js
316secret = readlineSync.question('Please whisper sweet words: ', {
317 hideEchoBack: true,
318 mask: require('chalk').magenta('\u2665')
319});
320```
321
322![sample](screen_02.gif)
323
324### <a name="basic_options-limit"></a>`limit`
325
326Limit the user's input.
327The usage differ depending on the method.
328
329#### <a name="basic_options-limit-for_question_and_prompt_methods"></a>For `question*` and `prompt*` methods
330
331*Type:* string, number, RegExp, function or Array
332*Default:* `[]`
333
334Accept only the input that matches value that is specified to this. If the user input others, display a string that is specified to [`limitMessage`](#basic_options-limitmessage) option, and wait for reinput.
335
336* The string is compared with the input. It is affected by [`caseSensitive`](#basic_options-casesensitive) option.
337* The number is compared with the input that is converted to number by `parseFloat()`. For example, it interprets `' 3.14 '`, `'003.1400'`, `'314e-2'` and `'3.14PI'` as `3.14`. And it interprets `'005'`, `'5files'`, `'5kb'` and `'5px'` as `5`.
338* The RegExp tests the input.
339* The function that returns a boolean to indicate whether it matches is called with the input.
340
341One of above or an Array that includes multiple things (or Array includes Array) can be specified.
342
343For example:
344
345```js
346command = readlineSync.prompt({limit: ['add', 'remove', /^clear( all)?$/]});
347// ** But `promptCL` method should be used instead of this. **
348```
349
350```js
351file = readlineSync.question('Text File: ', {limit: /\.txt$/i});
352// ** But `questionPath` method should be used instead of this. **
353```
354
355```js
356ip = readlineSync.question('IP Address: ', {limit: function(input) {
357 return require('net').isIP(input); // Valid IP Address
358}});
359```
360
361```js
362availableActions = [];
363if (!blockExists()) { availableActions.push('jump'); }
364if (isLarge(place)) { availableActions.push('run'); }
365if (isNew(shoes)) { availableActions.push('kick'); }
366if (isNearby(enemy)) { availableActions.push('punch'); }
367action = readlineSync.prompt({limit: availableActions});
368// ** But `promptCL` method should be used instead of this. **
369```
370
371#### <a name="basic_options-limit-for_keyin_method"></a>For `keyIn*` method
372
373*Type:* string, number or Array
374*Default:* `[]`
375
376Accept only the key that matches value that is specified to this, ignore others.
377Specify the characters as the key. All strings or Array of those are decomposed into single characters. For example, `'abcde'` or `['a', 'bc', ['d', 'e']]` are the same as `['a', 'b', 'c', 'd', 'e']`.
378These strings are compared with the input. It is affected by [`caseSensitive`](#basic_options-casesensitive) option.
379
380The [placeholders](#placeholders) like `'$<a-e>'` are replaced to an Array that is the character list like `['a', 'b', 'c', 'd', 'e']`.
381
382For example:
383
384```js
385direction = readlineSync.keyIn('Left or Right? ', {limit: 'lr'}); // 'l' or 'r'
386```
387
388```js
389dice = readlineSync.keyIn('Roll the dice, What will the result be? ',
390 {limit: '$<1-6>'}); // range of '1' to '6'
391```
392
393### <a name="basic_options-limitmessage"></a>`limitMessage`
394
395_For `question*` and `prompt*` methods only_
396*Type:* string
397*Default:* `'Input another, please.$<( [)limit(])>'`
398
399Display this to the user when the [`limit`](#basic_options-limit) option is specified and the user input others.
400The [placeholders](#placeholders) can be included.
401
402For example:
403
404```js
405file = readlineSync.question('Name of Text File: ', {
406 limit: /\.txt$/i,
407 limitMessage: 'Sorry, $<lastInput> is not text file.'
408});
409```
410
411### <a name="basic_options-defaultinput"></a>`defaultInput`
412
413_For `question*` and `prompt*` methods only_
414*Type:* string
415*Default:* `''`
416
417If the user input empty text (i.e. pressed the Enter key only), return this.
418
419For example:
420
421```js
422lang = readlineSync.question('Which language? ', {defaultInput: 'javascript'});
423```
424
425### <a name="basic_options-truevalue_falsevalue"></a>`trueValue`, `falseValue`
426
427*Type:* string, number, RegExp, function or Array
428*Default:* `[]`
429
430If the input matches `trueValue`, return `true`. If the input matches `falseValue`, return `false`. In any other case, return the input.
431
432* The string is compared with the input. It is affected by [`caseSensitive`](#basic_options-casesensitive) option.
433* The number is compared with the input that is converted to number by `parseFloat()`. For example, it interprets `' 3.14 '`, `'003.1400'`, `'314e-2'` and `'3.14PI'` as `3.14`. And it interprets `'005'`, `'5files'`, `'5kb'` and `'5px'` as `5`. Note that in `keyIn*` method, the input is every time one character (i.e. the number that is specified must be an integer within the range of `0` to `9`).
434* The RegExp tests the input.
435* The function that returns a boolean to indicate whether it matches is called with the input.
436
437One of above or an Array that includes multiple things (or Array includes Array) can be specified.
438
439For example:
440
441```js
442answer = readlineSync.question('How do you like it? ', {
443 trueValue: ['yes', 'yeah', 'yep'],
444 falseValue: ['no', 'nah', 'nope']
445});
446if (answer === true) {
447 console.log('Let\'s go!');
448} else if (answer === false) {
449 console.log('Oh... It\'s ok...');
450} else {
451 console.log('Sorry. What does "' + answer + '" you said mean?');
452}
453```
454
455### <a name="basic_options-casesensitive"></a>`caseSensitive`
456
457*Type:* boolean
458*Default:* `false`
459
460By default, the string comparisons are case-insensitive (i.e. `a` equals `A`). If `true` is specified, it is case-sensitive, the cases are not ignored (i.e. `a` is different from `A`).
461It affects: [`limit`](#basic_options-limit), [`trueValue`](#basic_options-truevalue_falsevalue), [`falseValue`](#basic_options-truevalue_falsevalue), some [placeholders](#placeholders), and some [Utility Methods](#utility_methods).
462
463### <a name="basic_options-keepwhitespace"></a>`keepWhitespace`
464
465_For `question*` and `prompt*` methods only_
466*Type:* boolean
467*Default:* `false`
468
469By default, remove the leading and trailing white spaces from the input text. If `true` is specified, don't remove those.
470
471### <a name="basic_options-encoding"></a>`encoding`
472
473*Type:* string
474*Default:* `'utf8'`
475
476Set the encoding method of the input and output.
477
478### <a name="basic_options-buffersize"></a>`bufferSize`
479
480_For `question*` and `prompt*` methods only_
481*Type:* number
482*Default:* `1024`
483
484When readlineSync reads from a console directly (without [external program](#note-reading_by_external_program)), use a size `bufferSize` buffer.
485Even if the input by user exceeds it, it's usually no problem, because the buffer is used repeatedly. But some platforms's (e.g. Windows) console might not accept input that exceeds it. And set an enough size.
486Note that this might be limited by [version of Node.js](https://nodejs.org/api/buffer.html#buffer_class_method_buffer_alloc_size_fill_encoding) and environment running your script (Big buffer size is usually not required). (See also: [issue](https://github.com/nodejs/node/issues/4660), [PR](https://github.com/nodejs/node/pull/4682))
487
488### <a name="basic_options-print"></a>`print`
489
490*Type:* function or `undefined`
491*Default:* `undefined`
492
493Call the specified function with every output. The function is given two arguments, `display` as an output text, and a value of [`encoding`](#basic_options-encoding) option.
494
495For example:
496
497* Pass the plain texts to the Logger (e.g. [log4js](https://github.com/nomiddlename/log4js-node)), after clean the colored texts.
498
499![sample](screen_01.png)
500
501```js
502var readlineSync = require('readline-sync'),
503 chalk = require('chalk'),
504 log4js = require('log4js'),
505 logger, user, pw, command;
506
507log4js.configure({appenders: [{type: 'file', filename: 'fooApp.log'}]});
508logger = log4js.getLogger('fooApp');
509
510readlineSync.setDefaultOptions({
511 print: function(display, encoding)
512 { logger.info(chalk.stripColor(display)); }, // Remove ctrl-chars.
513 prompt: chalk.red.bold('> ')
514});
515
516console.log(chalk.black.bold.bgYellow(' Your Account '));
517user = readlineSync.question(chalk.gray.underline(' USER NAME ') + ' : ');
518pw = readlineSync.question(chalk.gray.underline(' PASSWORD ') + ' : ',
519 {hideEchoBack: true});
520// Authorization ...
521console.log(chalk.green('Welcome, ' + user + '!'));
522command = readlineSync.prompt();
523```
524
525* Output a conversation to a file when an output stream is redirected to record those into a file like `your-script >foo.log`. That is, a conversation isn't outputted to `foo.log` without this code.
526
527```js
528readlineSync.setDefaultOptions({
529 print: function(display, encoding)
530 { process.stdout.write(display, encoding); }
531});
532var name = readlineSync.question('May I have your name? ');
533var loc = readlineSync.question('Hi ' + name + '! Where do you live? ');
534```
535
536* Let somebody hear our conversation in real time.
537It just uses a fifo with above sample code that was named `conv.js`.
538
539Another terminal:
540
541```console
542mkfifo /tmp/fifo
543cat /tmp/fifo
544```
545
546My terminal:
547
548```console
549node conv.js >/tmp/fifo
550```
551
552```console
553May I have your name? Oz
554Hi Oz! Where do you live? Emerald City
555```
556
557And then, another terminal shows this synchronously:
558
559```console
560May I have your name? Oz
561Hi Oz! Where do you live? Emerald City
562```
563
564### <a name="basic_options-history"></a>`history`
565
566_For `question*` and `prompt*` methods only_
567*Type:* boolean
568*Default:* `true`
569
570readlineSync supports a history expansion feature that is similar to that of the shell. If `false` is specified, disable this feature.
571*It keeps a previous input only.* That is, only `!!`, `!-1`, `!!:p` and `!-1:p` like bash or zsh etc. are supported.
572
573* `!!` or `!-1`: Return a previous input.
574* `!!:p` or `!-1:p`: Display a previous input but do not return it, and wait for reinput.
575
576For example:
577
578```js
579while (true) {
580 input = readlineSync.prompt();
581 console.log('-- You said "' + input + '"');
582}
583```
584
585```console
586> hello
587-- You said "hello"
588> !!
589hello
590-- You said "hello"
591> !!:p
592hello
593> bye
594-- You said "bye"
595```
596
597### <a name="basic_options-cd"></a>`cd`
598
599_For `question*` and `prompt*` methods only_
600*Type:* boolean
601*Default:* `false`
602
603readlineSync supports the changing the current working directory feature that is similar to the `cd` and `pwd` commands in the shell. If `true` is specified, enable this feature.
604This helps the user when you let the user input the multiple local files or directories.
605It supports `cd` and `pwd` commands.
606
607* `cd <path>`: Change the current working directory to `<path>`. The `<path>` can include `~` as the home directory.
608* `pwd`: Display the current working directory.
609
610When these were input, do not return, and wait for reinput.
611
612For example:
613
614```js
615while (true) {
616 file = readlineSync.questionPath('File: ');
617 console.log('-- Specified file is ' + file);
618}
619```
620
621```console
622File: cd foo-dir/bar-dir
623File: pwd
624/path/to/foo-dir/bar-dir
625File: file-a.js
626-- Specified file is /path/to/foo-dir/bar-dir/file-a.js
627File: file-b.png
628-- Specified file is /path/to/foo-dir/bar-dir/file-b.png
629File: file-c.html
630-- Specified file is /path/to/foo-dir/bar-dir/file-c.html
631```
632
633## <a name="utility_methods"></a>Utility Methods
634
635[`questionEMail`](#utility_methods-questionemail), [`questionNewPassword`](#utility_methods-questionnewpassword), [`questionInt`](#utility_methods-questionint), [`questionFloat`](#utility_methods-questionfloat), [`questionPath`](#utility_methods-questionpath), [`promptCL`](#utility_methods-promptcl), [`promptLoop`](#utility_methods-promptloop), [`promptCLLoop`](#utility_methods-promptclloop), [`promptSimShell`](#utility_methods-promptsimshell), [`keyInYN`](#utility_methods-keyinyn), [`keyInYNStrict`](#utility_methods-keyinynstrict), [`keyInPause`](#utility_methods-keyinpause), [`keyInSelect`](#utility_methods-keyinselect)
636
637These are convenient methods that are extended [Basic Methods](#basic_methods) to be used easily.
638
639### <a name="utility_methods-questionemail"></a>`questionEMail`
640
641```js
642email = readlineSync.questionEMail([query[, options]])
643```
644
645Display a `query` to the user if it's specified, and then accept only a valid e-mail address, and then return it after the Enter key was pressed.
646
647The `query` is handled the same as that of the [`question`](#basic_methods-question) method.
648The default value of `query` is `'Input e-mail address: '`.
649
650**Note:** The valid e-mail address requirement is a willful violation of [RFC5322](http://tools.ietf.org/html/rfc5322), this is defined in [HTML5](http://www.w3.org/TR/html5/forms.html). This works enough to prevent the user mistaking. If you want to change it, specify [`limit`](#basic_options-limit) option.
651
652For example:
653
654```js
655email = readlineSync.questionEMail();
656console.log('-- E-mail is ' + email);
657```
658
659```console
660Input e-mail address: abc
661Input valid e-mail address, please.
662Input e-mail address: mail@example.com
663-- E-mail is mail@example.com
664```
665
666#### <a name="utility_methods-questionemail-options"></a>Options
667
668The following options have independent default value that is not affected by [Default Options](#basic_options).
669
670| Option Name | Default Value |
671|-------------------|---------------|
672| [`hideEchoBack`](#basic_options-hideechoback) | `false` |
673| [`limit`](#basic_options-limit) | RegExp by [HTML5](http://www.w3.org/TR/html5/forms.html) |
674| [`limitMessage`](#basic_options-limitmessage) | `'Input valid e-mail address, please.'` |
675| [`trueValue`](#basic_options-truevalue_falsevalue) | `null` |
676| [`falseValue`](#basic_options-truevalue_falsevalue) | `null` |
677
678The following options work as shown in the [Basic Options](#basic_options) section.
679
680<table>
681<tr><td><a href="#basic_options-mask"><code>mask</code></a></td><td><a href="#basic_options-defaultinput"><code>defaultInput</code></a></td><td><a href="#basic_options-casesensitive"><code>caseSensitive</code></a></td><td><a href="#basic_options-encoding"><code>encoding</code></a></td><td><a href="#basic_options-buffersize"><code>bufferSize</code></a></td></tr>
682<tr><td><a href="#basic_options-print"><code>print</code></a></td><td><a href="#basic_options-history"><code>history</code></a></td></tr>
683</table>
684
685### <a name="utility_methods-questionnewpassword"></a>`questionNewPassword`
686
687```js
688password = readlineSync.questionNewPassword([query[, options]])
689```
690
691Display a `query` to the user if it's specified, and then accept only a valid password, and then request same one again, and then return it after the Enter key was pressed.
692It's the password, or something that is the secret text like the password.
693You can specify the valid password requirement to the options.
694
695The `query` is handled the same as that of the [`question`](#basic_methods-question) method.
696The default value of `query` is `'Input new password: '`.
697
698**Note:** Only the form of password is checked. Check it more if you want. For example, [zxcvbn](https://github.com/dropbox/zxcvbn) is password strength estimation library.
699
700For example:
701
702```js
703password = readlineSync.questionNewPassword();
704console.log('-- Password is ' + password);
705```
706
707```console
708Input new password: ************
709It can include: 0...9, A...Z, a...z, !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
710And the length must be: 12...24
711Input new password: *************
712Reinput a same one to confirm it: *************
713It differs from first one. Hit only the Enter key if you want to retry from first one.
714Reinput a same one to confirm it: *************
715-- Password is _my_password_
716```
717
718#### <a name="utility_methods-questionnewpassword-options"></a>Options
719
720The following options have independent default value that is not affected by [Default Options](#basic_options).
721
722| Option Name | Default Value |
723|-------------------|---------------|
724| [`hideEchoBack`](#basic_options-hideechoback) | `true` |
725| [`mask`](#basic_options-mask) | `'*'` |
726| [`limitMessage`](#basic_options-limitmessage) | `'It can include: $<charlist>\nAnd the length must be: $<length>'` |
727| [`trueValue`](#basic_options-truevalue_falsevalue) | `null` |
728| [`falseValue`](#basic_options-truevalue_falsevalue) | `null` |
729| [`caseSensitive`](#basic_options-casesensitive) | `true` |
730
731The following options work as shown in the [Basic Options](#basic_options) section.
732
733<table>
734<tr><td><a href="#basic_options-defaultinput"><code>defaultInput</code></a></td><td><a href="#basic_options-keepwhitespace"><code>keepWhitespace</code></a></td><td><a href="#basic_options-encoding"><code>encoding</code></a></td><td><a href="#basic_options-buffersize"><code>bufferSize</code></a></td><td><a href="#basic_options-print"><code>print</code></a></td></tr>
735</table>
736
737And the following additional options are available.
738
739##### <a name="utility_methods-questionnewpassword-options-charlist"></a>`charlist`
740
741*Type:* string
742*Default:* `'$<!-~>'`
743
744A string as the characters that can be included in the password. For example, if `'abc123'` is specified, the passwords that include any character other than these 6 characters are refused.
745The [placeholders](#placeholders) like `'$<a-e>'` are replaced to the characters like `'abcde'`.
746
747For example, let the user input a password that is created with alphabet and some symbols:
748
749```js
750password = readlineSync.questionNewPassword('PASSWORD: ', {charlist: '$<a-z>#$@%'});
751```
752
753##### <a name="utility_methods-questionnewpassword-options-min_max"></a>`min`, `max`
754
755*Type:* number
756*Default:* `min`: `12`, `max`: `24`
757
758`min`: A number as a minimum length of the password.
759`max`: A number as a maximum length of the password.
760
761##### <a name="utility_methods-questionnewpassword-options-confirmmessage"></a>`confirmMessage`
762
763*Type:* string or others
764*Default:* `'Reinput a same one to confirm it: '`
765
766A message that lets the user input the same password again.
767It can include the [placeholders](#placeholders).
768If this is not string, it is converted to string (i.e. `toString` method is called).
769
770##### <a name="utility_methods-questionnewpassword-options-unmatchmessage"></a>`unmatchMessage`
771
772*Type:* string or others
773*Default:* `'It differs from first one. Hit only the Enter key if you want to retry from first one.'`
774
775A warning message that is displayed when the second input did not match first one.
776This is converted the same as the [`confirmMessage`](#utility_methods-questionnewpassword-options-confirmmessage) option.
777
778#### <a name="utility_methods-questionnewpassword-additional_placeholders"></a>Additional Placeholders
779
780The following additional [placeholder](#placeholders) parameters are available.
781
782##### <a name="utility_methods-questionnewpassword-additional_placeholders-charlist"></a>`charlist`
783
784A current value of [`charlist`](#utility_methods-questionnewpassword-options-charlist) option that is converted to human readable if possible. (e.g. `'A...Z'`)
785
786##### <a name="utility_methods-questionnewpassword-additional_placeholders-length"></a>`length`
787
788A current value of [`min` and `max`](#utility_methods-questionnewpassword-options-min_max) option that is converted to human readable. (e.g. `'12...24'`)
789
790### <a name="utility_methods-questionint"></a>`questionInt`
791
792```js
793numInt = readlineSync.questionInt([query[, options]])
794```
795
796Display a `query` to the user if it's specified, and then accept only an input that can be interpreted as an integer, and then return the number (not string) after the Enter key was pressed.
797This parses the input as much as possible by `parseInt()`. For example, it interprets `' 5 '`, `'5.6'`, `'005'`, `'5files'`, `'5kb'` and `'5px'` as `5`.
798
799The `query` is handled the same as that of the [`question`](#basic_methods-question) method.
800
801#### <a name="utility_methods-questionint-options"></a>Options
802
803The following option has independent default value that is not affected by [Default Options](#basic_options).
804
805| Option Name | Default Value |
806|-------------------|---------------|
807| [`limitMessage`](#basic_options-limitmessage) | `'Input valid number, please.'` |
808
809The following options work as shown in the [Basic Options](#basic_options) section.
810
811<table>
812<tr><td><a href="#basic_options-hideechoback"><code>hideEchoBack</code></a></td><td><a href="#basic_options-mask"><code>mask</code></a></td><td><a href="#basic_options-defaultinput"><code>defaultInput</code></a></td><td><a href="#basic_options-encoding"><code>encoding</code></a></td><td><a href="#basic_options-buffersize"><code>bufferSize</code></a></td></tr>
813<tr><td><a href="#basic_options-print"><code>print</code></a></td><td><a href="#basic_options-history"><code>history</code></a></td></tr>
814</table>
815
816### <a name="utility_methods-questionfloat"></a>`questionFloat`
817
818```js
819numFloat = readlineSync.questionFloat([query[, options]])
820```
821
822Display a `query` to the user if it's specified, and then accept only an input that can be interpreted as a floating-point number, and then return the number (not string) after the Enter key was pressed.
823This parses the input as much as possible by `parseFloat()`. For example, it interprets `' 3.14 '`, `'003.1400'`, `'314e-2'` and `'3.14PI'` as `3.14`.
824
825The `query` is handled the same as that of the [`question`](#basic_methods-question) method.
826
827#### <a name="utility_methods-questionfloat-options"></a>Options
828
829The following option has independent default value that is not affected by [Default Options](#basic_options).
830
831| Option Name | Default Value |
832|-------------------|---------------|
833| [`limitMessage`](#basic_options-limitmessage) | `'Input valid number, please.'` |
834
835The following options work as shown in the [Basic Options](#basic_options) section.
836
837<table>
838<tr><td><a href="#basic_options-hideechoback"><code>hideEchoBack</code></a></td><td><a href="#basic_options-mask"><code>mask</code></a></td><td><a href="#basic_options-defaultinput"><code>defaultInput</code></a></td><td><a href="#basic_options-encoding"><code>encoding</code></a></td><td><a href="#basic_options-buffersize"><code>bufferSize</code></a></td></tr>
839<tr><td><a href="#basic_options-print"><code>print</code></a></td><td><a href="#basic_options-history"><code>history</code></a></td></tr>
840</table>
841
842### <a name="utility_methods-questionpath"></a>`questionPath`
843
844```js
845path = readlineSync.questionPath([query[, options]])
846```
847
848Display a `query` to the user if it's specified, and then accept only a valid local file or directory path, and then return an absolute path after the Enter key was pressed.
849The `~` that is input by the user is replaced to the home directory.
850You can specify the valid local file or directory path requirement to the options. And you can make it create a new file or directory when it doesn't exist.
851
852It is recommended to use this method with the [`cd`](#basic_options-cd) option. (Default: `true`)
853
854The `query` is handled the same as that of the [`question`](#basic_methods-question) method.
855The default value of `query` is `'Input path (you can "cd" and "pwd"): '`.
856
857For example:
858
859```js
860sourceFile = readlineSync.questionPath('Read from: ', {
861 isFile: true
862});
863console.log('-- sourceFile: ' + sourceFile);
864
865saveDir = readlineSync.questionPath('Save to: ', {
866 isDirectory: true,
867 exists: null,
868 create: true
869});
870console.log('-- saveDir: ' + saveDir);
871```
872
873```console
874Read from: ~/fileA
875No such file or directory: /home/user/fileA
876Input valid path, please.
877Read from: pwd
878/path/to/work
879Read from: cd ~/project-1
880Read from: fileA
881-- sourceFile: /home/user/project-1/fileA
882Save to: ~/deploy/data
883-- saveDir: /home/user/deploy/data
884```
885
886#### <a name="utility_methods-questionpath-options"></a>Options
887
888The following options have independent default value that is not affected by [Default Options](#basic_options).
889
890| Option Name | Default Value |
891|-------------------|---------------|
892| [`hideEchoBack`](#basic_options-hideechoback) | `false` |
893| [`limitMessage`](#basic_options-limitmessage) | `'$<error(\n)>Input valid path, please.$<( Min:)min>$<( Max:)max>'` |
894| [`history`](#basic_options-history) | `true` |
895| [`cd`](#basic_options-cd) | `true` |
896
897The following options work as shown in the [Basic Options](#basic_options) section.
898
899<table>
900<tr><td><a href="#basic_options-mask"><code>mask</code></a></td><td><a href="#basic_options-defaultinput"><code>defaultInput</code></a></td><td><a href="#basic_options-encoding"><code>encoding</code></a></td><td><a href="#basic_options-buffersize"><code>bufferSize</code></a></td><td><a href="#basic_options-print"><code>print</code></a></td></tr>
901</table>
902
903And the following additional options are available.
904
905**Note:** It does not check the coherency about a combination of the options as the path requirement. For example, the `{exists: false, isFile: true}` never check that it is a file because it is limited to the path that does not exist.
906
907##### <a name="utility_methods-questionpath-options-exists"></a>`exists`
908
909*Type:* boolean or others
910*Default:* `true`
911
912If `true` is specified, accept only a file or directory path that exists. If `false` is specified, accept only a file or directory path that does *not* exist.
913In any other case, the existence is not checked.
914
915##### <a name="utility_methods-questionpath-options-min_max"></a>`min`, `max`
916
917*Type:* number or others
918*Default:* `undefined`
919
920`min`: A number as a minimum size of the file that is accepted.
921`max`: A number as a maximum size of the file that is accepted.
922If it is not specified or `0` is specified, the size is not checked. (A size of directory is `0`.)
923
924##### <a name="utility_methods-questionpath-options-isfile_isdirectory"></a>`isFile`, `isDirectory`
925
926*Type:* boolean
927*Default:* `false`
928
929`isFile`: If `true` is specified, accept only a file path.
930`isDirectory`: If `true` is specified, accept only a directory path.
931
932##### <a name="utility_methods-questionpath-options-validate"></a>`validate`
933
934*Type:* function or `undefined`
935*Default:* `undefined`
936
937If a function that returns `true` or an error message is specified, call it with a path that was input, and accept the input when the function returned `true`.
938If the function returned a string as an error message, that message is got by the [`error`](#utility_methods-questionpath-additional_placeholders-error) additional [placeholder](#placeholders) parameter.
939A path that was input is parsed before it is passed to the function. `~` is replaced to a home directory, and a path is converted to an absolute path.
940This is also a return value from this method.
941
942For example, accept only PNG file or tell it to the user:
943
944```js
945imageFile = readlineSync.questionPath('Image File: ', {
946 validate: function(path) { return /\.png$/i.test(path) || 'It is not PNG'; }
947});
948```
949
950##### <a name="utility_methods-questionpath-options-create"></a>`create`
951
952*Type:* boolean
953*Default:* `false`
954
955If `true` is specified, create a file or directory as a path that was input when it doesn't exist. If `true` is specified to the [`isDirectory`](#utility_methods-questionpath-options-isfile_isdirectory) option, create a directory, otherwise a file.
956It does not affect the existence check. Therefore, you can get a new file or directory path anytime by specifying: `{exists: false, create: true}`
957
958#### <a name="utility_methods-questionpath-additional_placeholders"></a>Additional Placeholders
959
960The following additional [placeholder](#placeholders) parameters are available.
961
962##### <a name="utility_methods-questionpath-additional_placeholders-error"></a>`error`
963
964An error message when the input was not accepted.
965This value is set by readlineSync, or the function that was specified to [`validate`](#utility_methods-questionpath-options-validate) option.
966
967##### <a name="utility_methods-questionpath-additional_placeholders-min_max"></a>`min`, `max`
968
969A current value of [`min` and `max`](#utility_methods-questionpath-options-min_max) option.
970
971### <a name="utility_methods-promptcl"></a>`promptCL`
972
973```js
974argsArray = readlineSync.promptCL([commandHandler[, options]])
975```
976
977Display a prompt-sign (see [`prompt`](#basic_options-prompt) option) to the user, and then consider the input as a command-line and parse it, and then return a result after the Enter key was pressed.
978A return value is an Array that includes the tokens that were parsed. It parses the input from the user as the command-line, and it interprets whitespaces, quotes, etc., and it splits it to tokens properly. Usually, a first element of the Array is command-name, and remaining elements are arguments.
979
980For example:
981
982```js
983argsArray = readlineSync.promptCL();
984console.log(argsArray.join('\n'));
985```
986
987```console
988> command arg "arg" " a r g " "" 'a"r"g' "a""rg" "arg
989command
990arg
991arg
992 a r g
993
994a"r"g
995arg
996arg
997```
998
999#### <a name="utility_methods-promptcl-commandhandler"></a>`commandHandler`
1000
1001By using the `commandHandler` argument, this method will come into its own. Specifying the Object to this argument has the more merit. And it has the more merit for [`promptCLLoop`](#utility_methods-promptclloop) method.
1002
1003If a function is specified to `commandHandler` argument, it is just called with a parsed Array as an argument list of the function. And `this` is an original input string, in the function.
1004
1005For example, the following 2 codes work same except that `this` is enabled in the second one:
1006
1007```js
1008argsArray = readlineSync.promptCL();
1009if (argsArray[0] === 'add') {
1010 console.log(argsArray[1] + ' is added.');
1011} else if (argsArray[0] === 'copy') {
1012 console.log(argsArray[1] + ' is copied to ' + argsArray[2] + '.');
1013}
1014```
1015
1016```js
1017readlineSync.promptCL(function(command, arg1, arg2) {
1018 console.log('You want to: ' + this); // All of command-line.
1019 if (command === 'add') {
1020 console.log(arg1 + ' is added.');
1021 } else if (command === 'copy') {
1022 console.log(arg1 + ' is copied to ' + arg2 + '.');
1023 }
1024});
1025```
1026
1027If an Object that has properties named as the command-name is specified, the command-name is interpreted, and a function as the value of matched property is called. A function is chosen properly by handling case of the command-name in accordance with the [`caseSensitive`](#basic_options-casesensitive) option.
1028The function is called with a parsed Array that excludes a command-name (i.e. first element is removed from the Array) as an argument list of the function.
1029That is, a structure of the `commandHandler` Object looks like:
1030
1031```js
1032{
1033 commandA: function(arg) { ... }, // commandA requires one argument.
1034 commandB: function(arg1, arg2) { ... }, // readlineSync doesn't care those.
1035 commandC: function() { ... } // Of course, it can also ignore all.
1036}
1037```
1038
1039readlineSync just receives the arguments from the user and passes those to these functions without checking. The functions may have to check whether the required argument was input by the user, and more validate those.
1040
1041For example, the following code works same to the above code:
1042
1043```js
1044readlineSync.promptCL({
1045 add: function(element) { // It's called by also "ADD", "Add", "aDd", etc..
1046 console.log(element + ' is added.');
1047 },
1048 copy: function(from, to) {
1049 console.log(from + ' is copied to ' + to + '.');
1050 }
1051});
1052```
1053
1054If the matched property is not found in the Object, a `_` property is chosen, and the function as the value of this property is called with a parsed Array as an argument list of the function. Note that this includes a command-name. That is, the function looks like `function(command, arg1, arg2, ...) { ... }`.
1055And if the Object doesn't have a `_` property, any command that the matched property is not found in the Object is refused.
1056
1057For example:
1058
1059```js
1060readlineSync.promptCL({
1061 copy: function(from, to) { // command-name is not included.
1062 console.log(from + ' is copied to ' + to + '.');
1063 },
1064 _: function(command) { // command-name is included.
1065 console.log('Sorry, ' + command + ' is not available.');
1066 }
1067});
1068```
1069
1070#### <a name="utility_methods-promptcl-options"></a>Options
1071
1072The following options have independent default value that is not affected by [Default Options](#basic_options).
1073
1074| Option Name | Default Value |
1075|-------------------|---------------|
1076| [`hideEchoBack`](#basic_options-hideechoback) | `false` |
1077| [`limitMessage`](#basic_options-limitmessage) | `'Requested command is not available.'` |
1078| [`caseSensitive`](#basic_options-casesensitive) | `false` |
1079| [`history`](#basic_options-history) | `true` |
1080
1081The following options work as shown in the [Basic Options](#basic_options) section.
1082
1083<table>
1084<tr><td><a href="#basic_options-prompt"><code>prompt</code></a></td><td><a href="#basic_options-mask"><code>mask</code></a></td><td><a href="#basic_options-defaultinput"><code>defaultInput</code></a></td><td><a href="#basic_options-encoding"><code>encoding</code></a></td><td><a href="#basic_options-buffersize"><code>bufferSize</code></a></td></tr>
1085<tr><td><a href="#basic_options-print"><code>print</code></a></td><td><a href="#basic_options-cd"><code>cd</code></a></td></tr>
1086</table>
1087
1088### <a name="utility_methods-promptloop"></a>`promptLoop`
1089
1090```js
1091readlineSync.promptLoop(inputHandler[, options])
1092```
1093
1094Display a prompt-sign (see [`prompt`](#basic_options-prompt) option) to the user, and then call `inputHandler` function with the input from the user after it has been typed and the Enter key was pressed. Do these repeatedly until `inputHandler` function returns `true`.
1095
1096For example, the following 2 codes work same:
1097
1098```js
1099while (true) {
1100 input = readlineSync.prompt();
1101 console.log('-- You said "' + input + '"');
1102 if (input === 'bye') {
1103 break;
1104 }
1105}
1106console.log('It\'s exited from loop.');
1107```
1108
1109```js
1110readlineSync.promptLoop(function(input) {
1111 console.log('-- You said "' + input + '"');
1112 return input === 'bye';
1113});
1114console.log('It\'s exited from loop.');
1115```
1116
1117```console
1118> hello
1119-- You said "hello"
1120> good morning
1121-- You said "good morning"
1122> bye
1123-- You said "bye"
1124It's exited from loop.
1125```
1126
1127#### <a name="utility_methods-promptloop-options"></a>Options
1128
1129The following options have independent default value that is not affected by [Default Options](#basic_options).
1130
1131| Option Name | Default Value |
1132|-------------------|---------------|
1133| [`hideEchoBack`](#basic_options-hideechoback) | `false` |
1134| [`trueValue`](#basic_options-truevalue_falsevalue) | `null` |
1135| [`falseValue`](#basic_options-truevalue_falsevalue) | `null` |
1136| [`caseSensitive`](#basic_options-casesensitive) | `false` |
1137| [`history`](#basic_options-history) | `true` |
1138
1139The other options work as shown in the [Basic Options](#basic_options) section.
1140
1141### <a name="utility_methods-promptclloop"></a>`promptCLLoop`
1142
1143```js
1144readlineSync.promptCLLoop([commandHandler[, options]])
1145```
1146
1147Execute [`promptCL`](#utility_methods-promptcl) method repeatedly until chosen [`commandHandler`](#utility_methods-promptcl-commandhandler) returns `true`.
1148The [`commandHandler`](#utility_methods-promptcl-commandhandler) may be a function that is called like:
1149
1150```js
1151exit = allCommands(command, arg1, arg2, ...);
1152```
1153
1154or an Object that has the functions that are called like:
1155
1156```js
1157exit = foundCommand(arg1, arg2, ...);
1158```
1159
1160See [`promptCL`](#utility_methods-promptcl) method for details.
1161This method looks like a combination of [`promptCL`](#utility_methods-promptcl) method and [`promptLoop`](#utility_methods-promptloop) method.
1162
1163For example:
1164
1165```js
1166readlineSync.promptCLLoop({
1167 add: function(element) {
1168 console.log(element + ' is added.');
1169 },
1170 copy: function(from, to) {
1171 console.log(from + ' is copied to ' + to + '.');
1172 },
1173 bye: function() { return true; }
1174});
1175console.log('It\'s exited from loop.');
1176```
1177
1178```console
1179> add "New Hard Disk"
1180New Hard Disk is added.
1181> move filesOnOld "New Hard Disk"
1182Requested command is not available.
1183> copy filesOnOld "New Hard Disk"
1184filesOnOld is copied to New Hard Disk.
1185> bye
1186It's exited from loop.
1187```
1188
1189#### <a name="utility_methods-promptclloop-options"></a>Options
1190
1191The following options have independent default value that is not affected by [Default Options](#basic_options).
1192
1193| Option Name | Default Value |
1194|-------------------|---------------|
1195| [`hideEchoBack`](#basic_options-hideechoback) | `false` |
1196| [`limitMessage`](#basic_options-limitmessage) | `'Requested command is not available.'` |
1197| [`caseSensitive`](#basic_options-casesensitive) | `false` |
1198| [`history`](#basic_options-history) | `true` |
1199
1200The following options work as shown in the [Basic Options](#basic_options) section.
1201
1202<table>
1203<tr><td><a href="#basic_options-prompt"><code>prompt</code></a></td><td><a href="#basic_options-mask"><code>mask</code></a></td><td><a href="#basic_options-defaultinput"><code>defaultInput</code></a></td><td><a href="#basic_options-encoding"><code>encoding</code></a></td><td><a href="#basic_options-buffersize"><code>bufferSize</code></a></td></tr>
1204<tr><td><a href="#basic_options-print"><code>print</code></a></td><td><a href="#basic_options-cd"><code>cd</code></a></td></tr>
1205</table>
1206
1207### <a name="utility_methods-promptsimshell"></a>`promptSimShell`
1208
1209```js
1210input = readlineSync.promptSimShell([options])
1211```
1212
1213Display a prompt-sign that is similar to that of the user's shell to the user, and then return the input from the user after it has been typed and the Enter key was pressed.
1214This method displays a prompt-sign like:
1215
1216On Windows:
1217
1218```console
1219C:\Users\User\Path\To\Directory>
1220```
1221
1222On others:
1223
1224```console
1225user@host:~/path/to/directory$
1226```
1227
1228#### <a name="utility_methods-promptsimshell-options"></a>Options
1229
1230The following options have independent default value that is not affected by [Default Options](#basic_options).
1231
1232| Option Name | Default Value |
1233|-------------------|---------------|
1234| [`hideEchoBack`](#basic_options-hideechoback) | `false` |
1235| [`history`](#basic_options-history) | `true` |
1236
1237The other options other than [`prompt`](#basic_options-prompt) option work as shown in the [Basic Options](#basic_options) section.
1238
1239### <a name="utility_methods-keyinyn"></a>`keyInYN`
1240
1241```js
1242boolYesOrEmpty = readlineSync.keyInYN([query[, options]])
1243```
1244
1245Display a `query` to the user if it's specified, and then return a boolean or an empty string immediately a key was pressed by the user, **without pressing the Enter key**. Note that the user has no chance to change the input.
1246This method works like the `window.confirm` method of web browsers. A return value means "Yes" or "No" the user said. It differ depending on the pressed key:
1247
1248* `Y`: `true`
1249* `N`: `false`
1250* other: `''`
1251
1252The `query` is handled the same as that of the [`question`](#basic_methods-question) method.
1253The default value of `query` is `'Are you sure? '`.
1254
1255The keys other than `Y` and `N` are also accepted (If you want to know a user's wish explicitly, use [`keyInYNStrict`](#utility_methods-keyinynstrict) method). Therefore, if you let the user make an important decision (e.g. files are removed), check whether the return value is not *falsy*. That is, a default is "No".
1256
1257For example:
1258
1259```js
1260if (!readlineSync.keyInYN('Do you want to install this?')) {
1261 // Key that is not `Y` was pressed.
1262 process.exit();
1263}
1264// Do something...
1265```
1266
1267Or if you let the user stop something that must be done (e.g. something about the security), check whether the return value is `false` explicitly. That is, a default is "Yes".
1268
1269For example:
1270
1271```js
1272// Don't use `(!readlineSync.keyInYN())`.
1273if (readlineSync.keyInYN('Continue virus scan?') === false) {
1274 // `N` key was pressed.
1275 process.exit();
1276}
1277// Continue...
1278```
1279
1280#### <a name="utility_methods-keyinyn-options"></a>Options
1281
1282The following options work as shown in the [Basic Options](#basic_options) section.
1283
1284<table>
1285<tr><td><a href="#basic_options-encoding"><code>encoding</code></a></td><td><a href="#basic_options-print"><code>print</code></a></td></tr>
1286</table>
1287
1288And the following additional option is available.
1289
1290##### <a name="utility_methods-keyinyn-options-guide"></a>`guide`
1291
1292*Type:* boolean
1293*Default:* `true`
1294
1295If `true` is specified, a string `'[y/n]'` as guide for the user is added to `query`. And `':'` is moved to the end of `query`, or it is added.
1296
1297For example:
1298
1299```js
1300readlineSync.keyInYN('Do you like me?'); // No colon
1301readlineSync.keyInYN('Really? :'); // Colon already exists
1302```
1303
1304```console
1305Do you like me? [y/n]: y
1306Really? [y/n]: y
1307```
1308
1309### <a name="utility_methods-keyinynstrict"></a>`keyInYNStrict`
1310
1311```js
1312boolYes = readlineSync.keyInYNStrict([query[, options]])
1313```
1314
1315Display a `query` to the user if it's specified, and then accept only `Y` or `N` key, and then return a boolean immediately it was pressed by the user, **without pressing the Enter key**. Note that the user has no chance to change the input.
1316This method works like the `window.confirm` method of web browsers. A return value means "Yes" or "No" the user said. It differ depending on the pressed key:
1317
1318* `Y`: `true`
1319* `N`: `false`
1320
1321The `query` is handled the same as that of the [`question`](#basic_methods-question) method.
1322The default value of `query` is `'Are you sure? '`.
1323
1324A key other than `Y` and `N` is not accepted. That is, a return value has no default. Therefore, the user has to tell an own wish explicitly. If you want to know a user's wish easily, use [`keyInYN`](#utility_methods-keyinyn) method.
1325
1326This method works same to [`keyInYN`](#utility_methods-keyinyn) method except that this accept only `Y` or `N` key (Therefore, a return value is boolean every time). The options also work same to [`keyInYN`](#utility_methods-keyinyn) method.
1327
1328### <a name="utility_methods-keyinpause"></a>`keyInPause`
1329
1330```js
1331readlineSync.keyInPause([query[, options]])
1332```
1333
1334Display a `query` to the user if it's specified, and then just wait for a key to be pressed by the user.
1335This method works like the `window.alert` method of web browsers. This is used to make the running of script pause and show something to the user, or wait for the user to be ready.
1336By default, any key is accepted (See: [Note](#utility_methods-keyinpause-note)). You can change this behavior by specifying [`limit`](#basic_options-limit) option (e.g. accept only a Space Bar).
1337
1338The `query` is handled the same as that of the [`question`](#basic_methods-question) method.
1339The default value of `query` is `'Continue...'`.
1340
1341For example:
1342
1343```js
1344// Have made the preparations for something...
1345console.log('==== Information of Your Computer ====');
1346console.log(info); // This can be `query`.
1347readlineSync.keyInPause();
1348console.log('It\'s executing now...');
1349// Do something...
1350```
1351
1352```console
1353==== Information of Your Computer ====
1354FOO: 123456
1355BAR: abcdef
1356Continue... (Hit any key)
1357It's executing now...
1358```
1359
1360#### <a name="utility_methods-keyinpause-options"></a>Options
1361
1362The following option has independent default value that is not affected by [Default Options](#basic_options).
1363
1364| Option Name | Default Value |
1365|-------------------|---------------|
1366| [`limit`](#basic_options-limit) | `null` |
1367
1368The following options work as shown in the [Basic Options](#basic_options) section.
1369
1370<table>
1371<tr><td><a href="#basic_options-casesensitive"><code>caseSensitive</code></a></td><td><a href="#basic_options-encoding"><code>encoding</code></a></td><td><a href="#basic_options-print"><code>print</code></a></td></tr>
1372</table>
1373
1374And the following additional option is available.
1375
1376##### <a name="utility_methods-keyinpause-options-guide"></a>`guide`
1377
1378*Type:* boolean
1379*Default:* `true`
1380
1381If `true` is specified, a string `'(Hit any key)'` as guide for the user is added to `query`.
1382
1383For example:
1384
1385```js
1386readlineSync.keyInPause('It\'s pausing now...');
1387```
1388
1389```console
1390It's pausing now... (Hit any key)
1391```
1392
1393#### <a name="utility_methods-keyinpause-note"></a>Note
1394
1395Control keys including Enter key are not accepted by `keyIn*` methods.
1396If you want to wait until the user presses Enter key, use `question*` methods instead of `keyIn*` methods. For example:
1397
1398```js
1399readlineSync.question('Hit Enter key to continue.', {hideEchoBack: true, mask: ''});
1400```
1401
1402### <a name="utility_methods-keyinselect"></a>`keyInSelect`
1403
1404```js
1405index = readlineSync.keyInSelect(items[, query[, options]])
1406```
1407
1408Display the list that was created with the `items` Array, and the `query` to the user if it's specified, and then return the number as an index of the `items` Array immediately it was chosen by pressing a key by the user, **without pressing the Enter key**. Note that the user has no chance to change the input.
1409
1410The `query` is handled the same as that of the [`question`](#basic_methods-question) method.
1411The default value of `query` is `'Choose one from list: '`.
1412
1413The minimum length of `items` Array is 1 and maximum length is 35. These elements are displayed as item list. A key to let the user choose an item is assigned to each item automatically in sequence like "1, 2, 3 ... 9, A, B, C ...". A number as an index of the `items` Array that corresponds to a chosen item by the user is returned.
1414
1415**Note:** Even if the `items` Array has only less than 35 items, a long Array that forces an user to scroll the list may irritate the user. Remember, the user might be in a console environment that doesn't support scrolling the screen. If you want to use a long `items` Array (e.g. more than 10 items), you should consider a "Pagination". (See [example](https://github.com/anseki/readline-sync/issues/60#issuecomment-324533678).)
1416
1417For example:
1418
1419```js
1420frameworks = ['Express', 'hapi', 'flatiron', 'MEAN.JS', 'locomotive'];
1421index = readlineSync.keyInSelect(frameworks, 'Which framework?');
1422console.log(frameworks[index] + ' is enabled.');
1423```
1424
1425```console
1426[1] Express
1427[2] hapi
1428[3] flatiron
1429[4] MEAN.JS
1430[5] locomotive
1431[0] CANCEL
1432
1433Which framework? [1...5 / 0]: 2
1434hapi is enabled.
1435```
1436
1437#### <a name="utility_methods-keyinselect-options"></a>Options
1438
1439The following option has independent default value that is not affected by [Default Options](#basic_options).
1440
1441| Option Name | Default Value |
1442|-------------------|---------------|
1443| [`hideEchoBack`](#basic_options-hideechoback) | `false` |
1444
1445The following options work as shown in the [Basic Options](#basic_options) section.
1446
1447<table>
1448<tr><td><a href="#basic_options-mask"><code>mask</code></a></td><td><a href="#basic_options-encoding"><code>encoding</code></a></td><td><a href="#basic_options-print"><code>print</code></a></td></tr>
1449</table>
1450
1451And the following additional options are available.
1452
1453##### <a name="utility_methods-keyinselect-options-guide"></a>`guide`
1454
1455*Type:* boolean
1456*Default:* `true`
1457
1458If `true` is specified, a string like `'[1...5]'` as guide for the user is added to `query`. And `':'` is moved to the end of `query`, or it is added. This is the key list that corresponds to the item list.
1459
1460##### <a name="utility_methods-keyinselect-options-cancel"></a>`cancel`
1461
1462*Type:* boolean, string or others
1463*Default:* `'CANCEL'`
1464
1465If a value other than `false` is specified, an item to let the user tell "cancel" is added to the item list. "[0] CANCEL" (default) is displayed, and if `0` key is pressed, `-1` is returned.
1466You can specify a label of this item other than `'CANCEL'`. A string such as `'Go back'` (empty string `''` also), something that is converted to string such as `Date`, a string that includes [placeholder](#placeholders) such as `'Next $<itemsCount> items'` are accepted.
1467
1468#### <a name="utility_methods-keyinselect-additional_placeholders"></a>Additional Placeholders
1469
1470The following additional [placeholder](#placeholders) parameters are available.
1471
1472##### <a name="utility_methods-keyinselect-additional_placeholders-itemscount"></a>`itemsCount`
1473
1474A length of a current `items` Array.
1475
1476For example:
1477
1478```js
1479items = ['item-A', 'item-B', 'item-C', 'item-D', 'item-E'];
1480index = readlineSync.keyInSelect(items, null,
1481 {cancel: 'Show more than $<itemsCount> items'});
1482```
1483
1484```console
1485[1] item-A
1486[2] item-B
1487[3] item-C
1488[4] item-D
1489[5] item-E
1490[0] Show more than 5 items
1491```
1492
1493##### <a name="utility_methods-keyinselect-additional_placeholders-firstitem"></a>`firstItem`
1494
1495A first item in a current `items` Array.
1496
1497For example:
1498
1499```js
1500index = readlineSync.keyInSelect(items, 'Choose $<firstItem> or another: ');
1501```
1502
1503##### <a name="utility_methods-keyinselect-additional_placeholders-lastitem"></a>`lastItem`
1504
1505A last item in a current `items` Array.
1506
1507For example:
1508
1509```js
1510items = ['January', 'February', 'March', 'April', 'May', 'June'];
1511index = readlineSync.keyInSelect(items, null,
1512 {cancel: 'In after $<lastItem>'});
1513```
1514
1515```console
1516[1] January
1517[2] February
1518[3] March
1519[4] April
1520[5] May
1521[6] June
1522[0] In after June
1523```
1524
1525## <a name="placeholders"></a>Placeholders
1526
1527[`hideEchoBack`, `mask`, `defaultInput`, `caseSensitive`, `keepWhitespace`, `encoding`, `bufferSize`, `history`, `cd`, `limit`, `trueValue`, `falseValue`](#placeholders-parameters-hideechoback_mask_defaultinput_casesensitive_keepwhitespace_encoding_buffersize_history_cd_limit_truevalue_falsevalue), [`limitCount`, `limitCountNotZero`](#placeholders-parameters-limitcount_limitcountnotzero), [`lastInput`](#placeholders-parameters-lastinput), [`history_mN`](#placeholders-parameters-historymn), [`cwd`, `CWD`, `cwdHome`](#placeholders-parameters-cwd_cwd_cwdhome), [`date`, `time`, `localeDate`, `localeTime`](#placeholders-parameters-date_time_localedate_localetime), [`C1-C2`](#placeholders-parameters-c1_c2)
1528
1529The placeholders in the text are replaced to another string.
1530
1531For example, the [`limitMessage`](#basic_options-limitmessage) option to display a warning message that means that the command the user requested is not available:
1532
1533```js
1534command = readlineSync.prompt({
1535 limit: ['add', 'remove'],
1536 limitMessage: '$<lastInput> is not available.'
1537});
1538```
1539
1540```console
1541> delete
1542delete is not available.
1543```
1544
1545The placeholders can be included in:
1546
1547* `query` argument
1548* [`prompt`](#basic_options-prompt) and [`limitMessage`](#basic_options-limitmessage) options
1549* [`limit` option for `keyIn*` method](#basic_options-limit-for_keyin_method) and [`charlist`](#utility_methods-questionnewpassword-options-charlist) option for [`questionNewPassword`](#utility_methods-questionnewpassword) method ([`C1-C2`](#placeholders-parameters-c1_c2) parameter only)
1550* And some additional options for the [Utility Methods](#utility_methods).
1551
1552### <a name="placeholders-syntax"></a>Syntax
1553
1554```
1555$<parameter>
1556```
1557
1558Or
1559
1560```
1561$<(text1)parameter(text2)>
1562```
1563
1564The placeholder is replaced to a string that is got by a `parameter`.
1565Both the `(text1)` and `(text2)` are optional.
1566A more added `'$'` at the left of the placeholder is used as an escape character, it disables a placeholder. For example, `'$$<foo>'` is replaced to `'$<foo>'`. If you want to put a `'$'` which is *not* an escape character at the left of a placeholder, specify it like `'$<($)bufferSize>'`, then it is replaced to `'$1024'`.
1567
1568At the each position of `'(text1)'` and `'(text2)'`, `'text1'` and `'text2'` are put when a string that was got by a `parameter` has more than 0 length. If that got string is `''`, a placeholder with or without `'(text1)'` and `'(text2)'` is replaced to `''`.
1569
1570For example, a warning message that means that the command the user requested is not available:
1571
1572```js
1573command = readlineSync.prompt({
1574 limit: ['add', 'remove'],
1575 limitMessage: 'Refused $<lastInput> you requested. Please input another.'
1576});
1577```
1578
1579```console
1580> give-me-car
1581Refused give-me-car you requested. Please input another.
1582```
1583
1584It looks like no problem.
1585But when the user input nothing (hit only the Enter key), and then a message is displayed:
1586
1587```console
1588>
1589Refused you requested. Please input another.
1590```
1591
1592This goes well:
1593
1594```js
1595command = readlineSync.prompt({
1596 limit: ['add', 'remove'],
1597 limitMessage: 'Refused $<lastInput( you requested)>. Please input another.'
1598});
1599```
1600
1601```console
1602>
1603Refused . Please input another.
1604```
1605
1606(May be more better: `'$<(Refused )lastInput( you requested. )>Please input another.'`)
1607
1608**Note:** The syntax `${parameter}` of older version is still supported, but this should not be used because it may be confused with template string syntax of ES6. And this will not be supported in due course of time.
1609
1610### <a name="placeholders-parameters"></a>Parameters
1611
1612The following parameters are available. And some additional parameters are available in the [Utility Methods](#utility_methods).
1613
1614#### <a name="placeholders-parameters-hideechoback_mask_defaultinput_casesensitive_keepwhitespace_encoding_buffersize_history_cd_limit_truevalue_falsevalue"></a>`hideEchoBack`, `mask`, `defaultInput`, `caseSensitive`, `keepWhitespace`, `encoding`, `bufferSize`, `history`, `cd`, `limit`, `trueValue`, `falseValue`
1615
1616A current value of each option.
1617It is converted to human readable if possible. The boolean value is replaced to `'on'` or `'off'`, and the Array is replaced to the list of only string and number elements.
1618And in the `keyIn*` method, the parts of the list as characters sequence are suppressed. For example, when `['a', 'b', 'c', 'd', 'e']` is specified to the [`limit`](#basic_options-limit) option, `'$<limit>'` is replaced to `'a...e'`. If `true` is specified to the [`caseSensitive`](#basic_options-casesensitive) option, the characters are converted to lower case.
1619
1620For example:
1621
1622```js
1623input = readlineSync.question(
1624 'Input something or the Enter key as "$<defaultInput>": ',
1625 {defaultInput: 'hello'}
1626);
1627```
1628
1629```console
1630Input something or the Enter key as "hello":
1631```
1632
1633#### <a name="placeholders-parameters-limitcount_limitcountnotzero"></a>`limitCount`, `limitCountNotZero`
1634
1635A length of a current value of the [`limit`](#basic_options-limit) option.
1636When the value of the [`limit`](#basic_options-limit) option is empty, `'$<limitCount>'` is replaced to `'0'`, `'$<limitCountNotZero>'` is replaced to `''`.
1637
1638For example:
1639
1640```js
1641action = readlineSync.question(
1642 'Choose action$<( from )limitCountNotZero( actions)>: ',
1643 {limit: availableActions}
1644);
1645```
1646
1647```console
1648Choose action from 5 actions:
1649```
1650
1651#### <a name="placeholders-parameters-lastinput"></a>`lastInput`
1652
1653A last input from the user.
1654In any case, this is saved.
1655
1656For example:
1657
1658```js
1659command = readlineSync.prompt({
1660 limit: availableCommands,
1661 limitMessage: '$<lastInput> is not available.'
1662});
1663```
1664
1665```console
1666> wrong-command
1667wrong-command is not available.
1668```
1669
1670#### <a name="placeholders-parameters-historymn"></a>`history_mN`
1671
1672When the history expansion feature is enabled (see [`history`](#basic_options-history) option), a current command line minus `N`.
1673*This feature keeps the previous input only.* That is, only `history_m1` is supported.
1674
1675For example:
1676
1677```js
1678while (true) {
1679 input = readlineSync.question('Something$<( or "!!" as ")history_m1(")>: ');
1680 console.log('-- You said "' + input + '"');
1681}
1682```
1683
1684```console
1685Something: hello
1686-- You said "hello"
1687Something or "!!" as "hello": !!
1688hello
1689-- You said "hello"
1690```
1691
1692#### <a name="placeholders-parameters-cwd_cwd_cwdhome"></a>`cwd`, `CWD`, `cwdHome`
1693
1694A current working directory.
1695
1696* `cwd`: A full-path
1697* `CWD`: A directory name
1698* `cwdHome`: A path that includes `~` as the home directory
1699
1700For example, like bash/zsh:
1701
1702```js
1703command = readlineSync.prompt({prompt: '[$<cwdHome>]$ '});
1704```
1705
1706```console
1707[~/foo/bar]$
1708```
1709
1710#### <a name="placeholders-parameters-date_time_localedate_localetime"></a>`date`, `time`, `localeDate`, `localeTime`
1711
1712A string as current date or time.
1713
1714* `date`: A date portion
1715* `time`: A time portion
1716* `localeDate`: A locality sensitive representation of the date portion based on system settings
1717* `localeTime`: A locality sensitive representation of the time portion based on system settings
1718
1719For example:
1720
1721```js
1722command = readlineSync.prompt({prompt: '[$<localeDate>]> '});
1723```
1724
1725```console
1726[04/21/2015]>
1727```
1728
1729#### <a name="placeholders-parameters-c1_c2"></a>`C1-C2`
1730
1731_For [`limit` option for `keyIn*` method](#basic_options-limit-for_keyin_method) and [`charlist`](#utility_methods-questionnewpassword-options-charlist) option for [`questionNewPassword`](#utility_methods-questionnewpassword) method only_
1732
1733A character list.
1734`C1` and `C2` are each single character as the start and the end. A sequence in ascending or descending order of characters ranging from `C1` to `C2` is created. For example, `'$<a-e>'` is replaced to `'abcde'`. `'$<5-1>'` is replaced to `'54321'`.
1735
1736For example, let the user input a password that is created with alphabet:
1737
1738```js
1739password = readlineSync.questionNewPassword('PASSWORD: ', {charlist: '$<a-z>'});
1740```
1741
1742See also [`limit` option for `keyIn*` method](#basic_options-limit-for_keyin_method).
1743
1744## Special method `getRawInput`
1745
1746```js
1747rawInput = readlineSync.getRawInput()
1748```
1749
1750Return a raw input data of last method.
1751When the input was terminated with no data, a `NULL` is inserted to the data.
1752
1753This might contain control-codes (e.g. `LF`, `CR`, `EOF`, etc.), therefore, it might be used to get `^D` that was input. But you should understand each environments for that. Or, **you should not use this** if your script is used in multiple environments.
1754For example, when the user input `EOF` (`^D` in Unix like system, `^Z` in Windows), `x1A` (`EOF`) is returned in Windows, and `x00` (`NULL`) is returned in Unix like system. And `x04` (`EOT`) is returned in Unix like system with raw-mode. And also, when [external program](#note-reading_by_external_program) is used, nothing is returned. See also [Control characters](#note-control_characters).
1755You may examine each environment and you must test your script very much, if you want to handle the raw input data.
1756
1757## <a name="with_task_runner"></a>With Task Runner
1758
1759The easy way to control a flow of the task runner by the input from the user:
1760
1761* [Grunt](http://gruntjs.com/) plugin: [grunt-confirm](https://github.com/anseki/grunt-confirm)
1762* [gulp](http://gulpjs.com/) plugin: [gulp-confirm](https://github.com/anseki/gulp-confirm)
1763
1764If you want to control a flow of the task runner (e.g. [Grunt](http://gruntjs.com/)), call readlineSync in a task callback that is called by the task runner. Then a flow of tasks is paused and it is controlled by the user.
1765
1766For example, by using [grunt-task-helper](https://github.com/anseki/grunt-task-helper):
1767
1768```console
1769$ grunt
1770Running "fileCopy" task
1771Files already exist:
1772 file-a.png
1773 file-b.js
1774Overwrite? [y/n]: y
1775file-a.png copied.
1776file-b.js copied.
1777Done.
1778```
1779
1780`Gruntfile.js`
1781
1782```js
1783grunt.initConfig({
1784 taskHelper: {
1785 fileCopy: {
1786 options: {
1787 handlerByTask: function() {
1788 // Abort the task if user don't want it.
1789 return readlineSync.keyInYN('Overwrite?');
1790 },
1791 filesArray: []
1792 },
1793 ...
1794 }
1795 },
1796 copy: {
1797 fileCopy: {
1798 files: '<%= taskHelper.fileCopy.options.filesArray %>'
1799 }
1800 }
1801});
1802```
1803
1804## <a name="note"></a>Note
1805
1806### <a name="note-platforms"></a>Platforms
1807
1808TTY interfaces are different by the platforms. If the platform doesn't support the interactively reading from TTY, an error is thrown.
1809
1810```js
1811try {
1812 answer = readlineSync.question('What is your favorite food? ');
1813} catch (e) {
1814 console.error(e);
1815 process.exit(1);
1816}
1817```
1818
1819### <a name="note-control_characters"></a>Control characters
1820
1821TTY interfaces are different by the platforms. In some environments, ANSI escape sequences might be ignored. For example, in non-POSIX TTY such as Windows CMD does not support it (that of Windows 8 especially has problems). Since readlineSync does not use Node.js library that emulates POSIX TTY (but that is still incomplete), those characters may be not parsed. Then, using ANSI escape sequences is not recommended if you will support more environments.
1822Also, control characters user input might be not accepted or parsed. That behavior differs depending on the environment. And current Node.js does not support controlling a readline system library.
1823
1824### <a name="note-reading_by_external_program"></a>Reading by external program
1825
1826readlineSync tries to read from a console by using the external program if it is needed (e.g. when the input stream is redirected on Windows XP). And if the running Node.js doesn't support the [Synchronous Process Execution](http://nodejs.org/api/child_process.html#child_process_synchronous_process_creation) (i.e. Node.js v0.10-), readlineSync uses "piping via files" for the synchronous execution.
1827As everyone knows, "piping via files" is no good. It blocks the event loop and a process. It might make the your script be slow.
1828
1829Why did I choose it? :
1830
1831* Good modules (native addon) for the synchronous execution exist, but node-gyp can't compile those in some platforms or Node.js versions.
1832* I think that the security is important more than the speed. Some modules have problem about security. Those don't protect the data. I think that the speed is not needed usually, because readlineSync is used while user types keys.
1833
1834## <a name="deprecated_methods_and_options"></a>Deprecated methods and options
1835
1836See [README-Deprecated.md](README-Deprecated.md).