-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
32 lines (28 loc) · 866 Bytes
/
server.js
File metadata and controls
32 lines (28 loc) · 866 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
const express = require('express');
const fs = require('fs');
const path = require('path');
const app = express();
const port = 3000;
app.get('/logs/app', (req, res) => {
const logFilePath = path.join(__dirname, 'app.log');
fs.readFile(logFilePath, 'utf8', (err, data) => {
if (err) {
res.status(500).send('Error reading log file');
return;
}
res.send(`<pre>${data}</pre>`);
});
});
app.get('/logs/folder/app', (req, res) => {
const logFilePath = path.join(__dirname, 'logs', 'app.log');
fs.readFile(logFilePath, 'utf8', (err, data) => {
if (err) {
res.status(500).send('Error reading log file');
return;
}
res.send(`<pre>${data}</pre>`);
});
});
app.listen(port, () => {
console.log(`Server is running at http://localhost:${port}`);
});