Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
55 lines (45 loc) · 1.37 KB
/
Copy pathindex.js
File metadata and controls
55 lines (45 loc) · 1.37 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
const http = require("http");
const rupiah = require("rupiah-format");
const fs = require("fs");
const os = require("os");
const host = "127.0.0.1";
const port = 3002;
// request adalah = data masuk dari luar
// response adalah = data keluar dari sistem
const server = http.createServer(function (request, response) {
const nama = "ALFIN BUDIYANTO";
let uang = 500000;
let jajan = 150000;
let sisa = uang - jajan;
uang = rupiah.convert(uang);
jajan = rupiah.convert(jajan);
sisa = rupiah.convert(sisa);
fs.appendFile("sisauang.txt", sisa, () => {
console.log("data uang berhasil disimpan");
});
const sisaRAM = os.freemem();
const jumlahCPU = os.cpus();
function checkCPU() {
let myCPU = [];
jumlahCPU.map((cpu, i) => {
myCPU.push(cpu.model);
});
return myCPU[0];
}
const hasil = `
<head>
<title>${nama}</title>
</head>
<body>
<h1 style='background: black; color: white; padding: 20px; text-align: center;'>NODE JS UANG JAJAN</h1>
<p>Halo nama saya ${nama}. saya jajan sebanyak ${jajan}, uang saya tadinya ${uang} sekarang menjadi ${sisa}.</p>
<h5>sisa RAM PC saya: ${sisaRAM}</h5>
<h5>merk CPU yang saya pake: ${checkCPU()}</h5>
</body>
`;
response.statusCode = 200;
response.end(hasil);
});
server.listen(port, host, function () {
console.log(`server menyala di ${host}:${port}`);
});