-
Notifications
You must be signed in to change notification settings - Fork 0
/
node_script.js
91 lines (75 loc) · 2.23 KB
/
node_script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Using node and the terminal
// https://www.dev2qa.com/node-js-get-user-input-from-command-line-prompt-example/
// Get process.stdin as the standard input object.
// var standard_input = process.stdin;
// // Set input character encoding.
// standard_input.setEncoding('utf-8');
// // Prompt user to input data in console.
// console.log('Please input text in command line.');
// // When user input data and click enter key.
// standard_input.on('data', function(data) {
// // User input exit.
// if (data === 'exit\n') {
// // Program exit.
// console.log('User input complete, program exit.');
// process.exit();
// } else {
// // Print user input in console.
// console.log('User Input Data : ' + data);
// }
// });
// https://flaviocopes.com/node-input-from-cli/
// const readline = require('readline').createInterface({
// input: process.stdin,
// output: process.stdout
// });
// readline.question(`What's your name?`, name => {
// console.log(`Hi ${name}!`);
// readline.close();
// });
// https://nodejs.org/api/readline.html
// https://node.readthedocs.io/en/latest/api/readline/
// https://github.com/dacogemini/hangman_node_version/blob/master/index.js
// https://www.npmjs.com/package/prompts
// https://github.com/sanquinluis/week11-hangman/tree/master/node_modules
// https://github.com/StefanieDing/Week11-Hangman
// const prompts = require('prompts');
// (async () => {
// const response = await prompts({
// type: 'text',
// name: 'guess',
// message: 'Make a guess'
// });
// if (response['guess'] === 'a') {
// console.log('That was a corrent guess!!');
// } else {
// console.log('Sorry that was wrong, you lose a life :(');
// }
// console.log(response); // => { value: 24 }
// })();
const prompts = require('prompts');
const questions = [
{
type: 'text',
name: 'username',
message: 'What is your GitHub username?'
},
{
type: 'number',
name: 'age',
message: 'How old are you?'
},
{
type: 'text',
name: 'about',
message: 'Tell something about yourself',
initial: 'Why should I?'
}
];
(async () => {
const response = await prompts(questions);
response => {
username, age, about;
};
console.log(response);
})();