fast72 commited on
Commit
fbcc222
·
verified ·
1 Parent(s): 4677ad4

Create app.js

Browse files
Files changed (1) hide show
  1. app.js +30 -0
app.js ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const express = require('express');
2
+ const path = require('path');
3
+ const fs = require('fs');
4
+ const app = express();
5
+ const PORT = 3000;
6
+
7
+ app.use(express.static(path.join(__dirname, 'public')));
8
+
9
+ function getFiles(directoryPath) {
10
+ let results = [];
11
+ const list = fs.readdirSync(directoryPath);
12
+ list.forEach(file => {
13
+ const filePath = path.join(directoryPath, file);
14
+ const stat = fs.statSync(filePath);
15
+ if (stat && stat.isDirectory()) {
16
+ results = results.concat(getFiles(filePath));
17
+ } else {
18
+ results.push(filePath.replace(__dirname, ''));
19
+ }
20
+ });
21
+ return results;
22
+ }
23
+
24
+ app.get('/file-list', (req, res) => {
25
+ res.json(getFiles(__dirname));
26
+ });
27
+
28
+ app.listen(PORT, () => {
29
+ console.log(`Server running on http://localhost:${PORT}`);
30
+ });