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}`); });