-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreadFile.js
More file actions
39 lines (27 loc) · 786 Bytes
/
readFile.js
File metadata and controls
39 lines (27 loc) · 786 Bytes
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
/*
Ask the user a questions. What file do you want to read?
When the user answers the questions, read the appropriate file and output the contents to the screen
*/
const readline = require(`readline`);
const fs = require(`fs`);
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
//placeholder for the user input
let newAnswer = "";
// this function prompts for user input
function readFile(){
rl.question(`What file do you want to read? `, (answer) => {
console.log(`Reading file: ${answer}`);
newAnswer = answer;
fs.readFile(newAnswer, "utf8", function (err,data) {
if (err) {
return console.log(err);
}
console.log(data);
});
rl.close();
});
}
readFile();