const express = require('express'); const fs = require('fs'); const path = require('path'); const app = express(); const PORT = 3000; const DIRECTORY = path.join(__dirname, 'tables'); // Change to your directory app.get('/', (req, res) => { fs.readdir(DIRECTORY, (err, files) => { if (err) return res.status(500).send('Error reading directory'); let html = '

File Index

'; res.send(html); }); }); app.get('/file/:filename', (req, res) => { const filename = req.params.filename; const filepath = path.join(DIRECTORY, filename); fs.readFile(filepath, 'utf8', (err, data) => { if (err) return res.status(404).send('File not found'); res.send(`

${filename}

${escapeHtml(data)}
Back`); }); }); function escapeHtml(text) { return text.replace(/[&<>"']/g, function(m) { return ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[m]; }); } app.listen(PORT, () => { console.log(`Server running at http://localhost:${PORT}`); });