File size: 817 Bytes
fbcc222 9d55072 fbcc222 |
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 express = require('express');
const path = require('path');
const fs = require('fs');
const app = express();
const PORT = 3000;
app.use('/', express.static(path.join(__dirname, 'public')));
function getFiles(directoryPath) {
let results = [];
const list = fs.readdirSync(directoryPath);
list.forEach(file => {
const filePath = path.join(directoryPath, file);
const stat = fs.statSync(filePath);
if (stat && stat.isDirectory()) {
results = results.concat(getFiles(filePath));
} else {
results.push(filePath.replace(__dirname, ''));
}
});
return results;
}
app.get('/file-list', (req, res) => {
res.json(getFiles(__dirname));
});
app.listen(PORT, () => {
console.log(`Server running on http://localhost:${PORT}`);
}); |