How to use the question function from readline-sync

Find comprehensive JavaScript readline-sync.question code examples handpicked from public code repositorys.

readline-sync.question is a method in Node.js that allows you to read input from the user in a console application.

11
12
13
14
15
16
17
18
19
20

```js
var readlineSync = require('readline-sync');

// Wait for user's response.
var userName = readlineSync.question('May I have your name? :');
console.log('Hi ' + userName + '!');

// Handle the secret text (e.g. password).
var favFood = readlineSync.question('What is your favorite food? :', {
fork icon61
star icon1
watch icon0

+ 63 other calls in file

39
40
41
42
43
44
45
46
47
    node = node || {}
    if (!node.endpoint) {
        node.endpoint = readlineSync.question('LXD endpoint: ')
    }
    if (!node.password) {
        node.password = readlineSync.question('LXD endpoint password: ', { hideEchoBack: true })
    }
    return node
}
fork icon8
star icon0
watch icon1

+ 125 other calls in file

How does readline-sync.question work?

readline-sync.question is a function that prompts the user to input a value by printing a message to the console and then waits for the user to enter a value through the command line interface, returning the value as a string.

9
10
11
12
13
14
15
16
17
18
  emailVerified: false,
  disabled: false
};

user.email = readlineSync.questionEMail('Please enter an Email:\n');
user.displayName = readlineSync.question("Please enter the Display Name:\n");

var isSamePassword = false;
while (!isSamePassword) {
    var password = readlineSync.question("Enter Password:\n", { hideEchoBack: true, keepWhitespace: true });
fork icon4
star icon15
watch icon3

+ 41 other calls in file

243
244
245
246
247
248
249
250
251
252
253


function particleLogin() {
  clear();
  //prompt for user and password
  var userName = readlineSync.questionEMail('Particle Username/Email:');
  var password = readlineSync.question('Particle Password:', {
    hideEchoBack: true // The typed text on screen is hidden by `*` (default). 
  });
  console.log('Logging in to Particle...'.green);
  spark.login({username: userName.trim(), password: password.trim()},loginCallback);
fork icon10
star icon13
watch icon0

+ 9 other calls in file

Ai Example

1
2
3
4
5
const readlineSync = require("readline-sync");

const name = readlineSync.question("What is your name? ");

console.log(`Hello, ${name}!`);

In this example, the readlineSync.question() method is used to prompt the user to enter their name. The text "What is your name?" is displayed as the prompt. The user's input is then stored in the name variable. Finally, the program prints out a greeting using the user's name.

3
4
5
6
7
8
9
10
11
12

var context = clone(base);
var lastAnswer = '';

context.doAsk = question => {
    lastAnswer = readline.question(question + '\n');
};

context.getLastAnswer = function(node) {
    return lastAnswer;
fork icon4
star icon9
watch icon3

+ 15 other calls in file

84
85
86
87
88
89
90
91
92
93
  {
    limit: /^\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$/
  }
)

data.projectVersion = readLineSync.question('> Project version (0.1.0): ') 
data.projectVersion = data.projectVersion === '' ? '0.1.0' : data.projectVersion

data.license = readLineSync.keyInSelect(
  licenses,
fork icon3
star icon0
watch icon0

+ 15 other calls in file

49
50
51
52
53
54
55
56
57
58
    await createUser(user)
    complete = true
  }
}
function askPassword () {
  let pass = readLine.question("Insert the user's password: ")
  if (pass === readLine.question("Retype the user's password: ")) {
    return pass
  } else {
    console.log("\x1b[31mPasswords doesn't match", '\x1b[0m')
fork icon2
star icon7
watch icon3

+ 41 other calls in file

208
209
210
211
212
213
214
215
216
217
)
config.email = readLineSync.questionEMail('> Email: ', {
  limit: EMAIL_REGEXP,
  limitMessage: 'That is not a valid email!'
})
config.version = readLineSync.question('> Project version (0.1.0): ')
config.version = config.version === '' ? PROJECT_VERSION : config.version
config.license = LICENSES[
  readLineSync.keyInSelect(LICENSES, '> Select your license: ', {
    cancel: false
fork icon0
star icon25
watch icon1

+ 14 other calls in file

6
7
8
9
10
11
12
13
14

class User {
  constructor() {
    this.nome = rs.question('Qual o seu nome? ');
    this.email = rs.questionEMail('Digite um endereço de e-mail: ');
    this.endereco = rs.question('Digite seu endereço: ');
    this.formasPagamento = rs.question('Digite uma forma de pagamento: ');
  }
}
fork icon60
star icon5
watch icon5

+ 41 other calls in file

36
37
38
39
40
41
42
43
44
45
}

function promptUserInfo(user) {
    user = user || {}
    if (!user.fullname) {
        user.fullname = readlineSync.question('Full name: ')
    }
    if (!user.email) {
        user.email = readlineSync.questionEMail('E-Mail address: ')
    }
fork icon8
star icon5
watch icon7

+ 83 other calls in file

21
22
23
24
25
26
27
28
29
30
    password: config.QB_ADMIN_PASSWORD,
  }
}

const email = readline.questionEMail(`Please enter your QuickBlox account owner email:\n`)
const password = readline.question(`Please enter your QuickBlox account owner password:\n`, { hideEchoBack: true })

return {
  email,
  password,
fork icon7
star icon5
watch icon6

+ 3 other calls in file

68
69
70
71
72
73
74
75
76
77
 */
const dataGenerator = function () {
    config.debugMode = true;
    let selectedMode = rls.question('Type collab or class to choose that mode: ');
    while (selectedMode !== 'collab' && selectedMode !== 'class') {
        selectedMode = rls.question('Unrecognized. Type either class or collab for your mode: ');
    }
    if (selectedMode === 'collab') {
        workingMode = common.modeTypes.COLLABORATORS;
    } else {
fork icon2
star icon5
watch icon4

+ 63 other calls in file

-3
console.log
fork icon1
star icon6
watch icon1

+ 7 other calls in file

107
108
109
110
111
112
113
114
115
116
        return ret;
}



function ask(s) { let arg = argv.shift();if (arg) { print(` Arg => ${arg}`);return arg; } return readlineSync.question(s); }

function plot_images(datas, display = true) {
        if (display) print(`-----------------------------------------------------`);
        if (display) print(` ---- Images ----`);
fork icon2
star icon3
watch icon1

+ 15 other calls in file

242
243
244
245
246
247
248
249
250
251
  '> Will this project be deployed with Heroku? ',
  {
    caseSensitive: false
  }
)
config.mainFile = readLineSync.question('> Main file (src/index.ts): ')
config.mainFile = config.mainFile === '' ? MAIN_FILE : config.mainFile
config.tests = readLineSync.keyInYNStrict(
  '> Would you want to have a basic suit of tests with Jest? ',
  {
fork icon0
star icon25
watch icon0

+ 3 other calls in file

21
22
23
24
25
26
27
28
29
30
31
32
reasons, but the session token identifying your login will be stored at \
${chalk.yellow(tools.getConfigDir())} (to change this, set your \
${chalk.grey("XDG_CONFIG_HOME")} environment variable).`);


    const sendEmail = rl.questionEMail("Sender account email: ");
    const sendPass = rl.question("Sender account password: ", tools.passOpts);
    const isSame = rl.keyInYN("Are the sender and receiver accounts the same?");


    getRecvCreds(isSame, sendEmail, sendPass, (recvEmail, recvPass) => {
        const shouldStore = askToStore();
fork icon0
star icon8
watch icon0

91
92
93
94
95
96
97
98
99
100
101
102
    }
}


function redoLogin(config, callback) {
    const email = rl.questionEMail("Sender account email: ");
    const pass = rl.question("Sender account password: ", tools.passOpts);
    const shouldStore = init.askToStore();


    init.storePrefs(email, pass, null, null, shouldStore, (_, __, ___, ____, _____, cb) => {
        // Dummy func to tell it to store the same receiver ID
fork icon0
star icon8
watch icon0

160
161
162
163
164
165
166
167
168
169
        cancel: allowedValues ? `${CBRIGHT}None${CRESET} - (No change)` : `${CBRIGHT}Manual enter a value${CRESET} - (Continue)`
    })
    if (index >= 0) {
        resultParameters[param] = stackParamteres[Object.keys(stackParamteres)[index]]
    } else if (!allowedValues) {
        resultParameters[param] = readlineSync.question(`\n * Enter parameter value for ${CPROMPT}${param}${CRESET} (${docYaml.Parameters[param].Default || ''}) :`) || docYaml.Parameters[param].Default
    }
}

function reviewParameters(resultParameters, stackParamteres, docYaml) {
fork icon0
star icon4
watch icon2

+ 27 other calls in file

-3
fork icon1
star icon2
watch icon0

+ 3 other calls in file

41
42
43
44
45
46
47
48
49
console.log('Nombre de usuario: ' + username);
puertoCliente = readlineSync.question('Escriba su numero de puerto: ');
ipCliente = readlineSync.question('Escriba su IP: ');
ipServidor = readlineSync.question('Escriba la IP del servidor: ');
do {
    ubicacion = readlineSync.question('Escriba la ubicación de las cosas: ');
} while (!validarUbicacion(ubicacion));
topicoMotor = 'ingenieria/anexo/' + ubicacion + '/motor';
topicoLED = 'ingenieria/anexo/' + ubicacion + '/led';
fork icon0
star icon2
watch icon1

+ 63 other calls in file