Created
July 18, 2023 23:01
-
-
Save jamesr2323/ba8671bb15eac88e157e5bb888bebf70 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const fs = require('fs-extra'); | |
const path = require('path'); | |
const app = express(); | |
const port = 3000; | |
app.use(express.static('./')); | |
app.get('/', async (req, res) => { | |
try { | |
const directoryPath = '.'; // Set your directory path here | |
const files = await fs.readdir(directoryPath); | |
const fileInfo = await Promise.all(files.map(async file => { | |
const filePath = path.join(directoryPath, file); | |
const stats = await fs.lstat(filePath); | |
return { | |
name: file, | |
path: filePath, | |
isDirectory: stats.isDirectory(), | |
size: stats.size, | |
}; | |
})); | |
res.json(fileInfo); | |
} catch (err) { | |
console.error(err); | |
res.status(500).send('Server error'); | |
} | |
}); | |
app.listen(port, () => { | |
console.log(`Server is running at http://localhost:${port}`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment