-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
30 lines (21 loc) · 767 Bytes
/
index.js
File metadata and controls
30 lines (21 loc) · 767 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
const dotenv = require('dotenv');
const express = require('express');
const morgan = require('morgan');
const fs = require('fs');
const path = require('path');
const app = express();
const port = process.env.PORT || 3000;
const accessLogStream = fs.createWriteStream(path.join(__dirname, 'access.log'), {flags: 'a'});
app.use(morgan('combined', {stream: accessLogStream}));
app.get('/', async (req, res) => {
const readStream = fs.createReadStream(path.join(__dirname, 'access.log'));
let streamoutput = '';
await readStream.on('data', (data) => {
streamoutput += data;
res.write(streamoutput);
}).on('end', () => {
console.log('done');
res.end('done');
});
});
app.listen(port, () => {console.log(`listening on port ${port}`)});