-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js_det
More file actions
41 lines (35 loc) · 1.12 KB
/
server.js_det
File metadata and controls
41 lines (35 loc) · 1.12 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
const fs = require('fs');
const express = require('express');
const app = express();
app.get('/', (req, res) => {
// Read the count from the file
let countText;
try {
countText = fs.readFileSync('./count.txt', 'utf-8');
} catch (error) {
// If the file doesn't exist or can't be read, default to 0
countText = '0';
}
const count = parseInt(countText);
console.log('Current count:', count);
const newCount = count + 1;
// Convert newCount to a string before writing
fs.writeFileSync('./count.txt', String(newCount));
res.send(`
<!DOCTYPE html>
<html lang="hu">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Weboldal</title>
</head>
<body>
<h1>Köszöntelek a weboldalamon</h1>
<p> Ez az oldal ${newCount}-szor lett meglátogatva. </p>
</body>
</html>
`);
});
app.listen(3000, () => {
console.log('Server is running on http://localhost:3000');
});