-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileTypeScanner.js
More file actions
30 lines (25 loc) · 811 Bytes
/
FileTypeScanner.js
File metadata and controls
30 lines (25 loc) · 811 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 fileAnalyzer = require('./FileTypes.js');
let fileSizes = fileAnalyzer('./');
console.log(fileSizes);
const http = require('http');
const fs = require('fs');
const path = require('path');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
const filePath = './index.html';
const contentType = 'text/html';
fs.readFile(filePath, (err, content) => {
if (err) {
res.writeHead(500);
res.end(`Error loading ${filePath}`);
} else {
const html = content.toString().replace('{{fileSizes}}', JSON.stringify(fileSizes));
res.writeHead(200, { 'Content-Type': contentType });
res.end(html, 'utf-8');
}
});
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});