-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathask.js
More file actions
56 lines (47 loc) · 1.22 KB
/
ask.js
File metadata and controls
56 lines (47 loc) · 1.22 KB
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
const fs = require("fs");
let answerStream;
let questions = [
"What is your name?",
"What would you rather be doing?",
"What is your preferred programming language?"
];
let answers = [];
function ask(i) {
process.stdout.write(`\n\n\n\n ${questions[i]}`);
process.stdout.write(` > `);
}
process.stdin.once("data", (data) => {
let name = data.toString().trim();
let fileName = `./${name}.md`;
if (fs.existsSync(fileName)) {
fs.unlinkSync(fileName);
}
answerStream = fs.createWriteStream(fileName);
answerStream.write(
`Question Amswers for ${name}\n=============\n`
)
});
process.stdin.on("data", function (data) {
let answer = data.toString().trim();
answerStream.write(
`Question: ${questions[answers.length]}\n`
);
answerStream.write(
`Answe: ${answer}`, function () {
if (answers.length < questions.length) {
ask(answers.length);
} else {
process.exit();
}
});
answers.push(answer);
});
process.on("exit", function () {
answerStream.close();
process.stdout.write("\n\n\n\n ");
process.stdout.write(
`Go ${answers[1]} ${answers[0]} you can finish writing ${answers[2]} later!`
);
process.stdout.write("\n\n\n\n");
});
ask(answers.length);