Answer the question
In order to leave comments, you need to log in
How to send all files from a folder to a website from a server?
I need that when the site loads, it displays all the mp3 files in the folder, that is, they must find their src. If I just sent 1 specific file, I would do it like this:
app.get("/getFile", (req, res) => {
res.sendFile(path.join(__dirname, "uploads", "имя файла"));
});
const music = fs.readdirSync(path.join(__dirname, "uploads"));
app.get("/getFile", (req, res) => {
res.sendFile(path.join(__dirname, "uploads", music[music.length - 1]));
});
Answer the question
In order to leave comments, you need to log in
Most likely you need a method for distributing static files:
app.use(express.static(path.join(__dirname, 'public')))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question