Spaces:
Runtime error
Runtime error
File size: 750 Bytes
b50804a 4a3e3b3 b50804a |
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 |
const express = require('express');
const fs = require('fs');
const path = require('path');
const app = express();
const PORT = process.env.PORT || 7860;
// Serve static files from public folder
app.use(express.static('public'));
// Endpoint to get the list of music files
app.get('/music-list', (req, res) => {
fs.readdir('./music', (err, files) => {
if (err) {
return res.sendStatus(500);
}
res.json(files);
});
});
// Endpoint to serve music files
app.get('/music/:filename', (req, res) => {
const { filename } = req.params;
const filepath = path.resolve(__dirname, 'music', filename);
res.sendFile(filepath);
});
app.listen(PORT, () => console.log(`Server listening on port ${PORT}`)); |