-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
66 lines (60 loc) · 1.69 KB
/
index.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
const http = require('http');
const fs = require('fs');
const readline = require('readline');
const hostname = "127.0.0.1";
const port = 3000;
//criar novo arquivo
/*
fs.writeFile('teste.txt','Teste de Escrita em arquivo',(err)=>{
if(err) throw err;
console.log('O arquivo foi criado com sucesso!')
})
*/
//cria novo arquivo ou insere conteudo depois do que já existe
// fs.appendFile('teste.txt',"\nOutro Conteúdo!",(err)=>{
// if (err) throw err;
// console.log('Nova linha salva com sucesso!');
// })
//lê arquivo
// fs.readFile('teste.txt',(err,data)=>{
// if(err) throw err;
// let str = data.toString();
// let newStr = str.substr(0,10);
// console.log(newStr);
// })
// Deletar arquivo
// fs.unlink('teste.txt',(err)=>{
// if(err) throw err;
// console.log('Arquivo excluido com sucesso!');
// })
// // Renomer arquivo
// fs.rename('teste.txt','NewTeste.txt',(err)=>{
// if(err) throw err;
// console.log("Renomeado com sucesso!");
// })
// const server = http.createServer((req,res)=>{
// fs.readFile('index.html',function(err,data){
// console.log(req.headers);
// res.writeHead(200,{'Content-Type':'text/html'});
// res.write(data);
// return res.end();
// })
// });
// server.listen(port,hostname,()=>{
// console.log("servidor está on-line");
// });
//lendo inputs
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question('Qual seu nome?',(name)=>{
console.log('O nome do usuario é: '+name);
rl.question('Qual sua idade?',(idade)=>{
console.log('A idade é: '+idade);
});
})
rl.on('close',()=>{
console.log('Adeus!');
process.exit(0);
});