leak / app.js
fast72's picture
Update app.js
9d55072 verified
raw
history blame contribute delete
817 Bytes
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}`);
});