Can someone explain to me how static serving .mp3 files works? #5176
Unanswered
zanzlender
asked this question in
Q&A
Replies: 1 comment
-
Why wasn't there anything in the devtools?There is no difference in the way that Express handles mp3 and image files. You probably didn't see any request, because devtools were opened after the request was made. Firefox devtools record network request only if they are open. My short demonstration: 2023-04-28.13-45-42.mp4Code used: const express = require("express");
const fs = require("node:fs");
const app = express();
app.use("/static", express.static("./static"));
app.get("/", (req, res, next) => {
fs.readdir("./static", { withFileTypes: true }, (err, files) => {
if (err) return next(err);
const links = files
.filter((f) => f.isFile())
.map((f) => `<li><a href="/static/${encodeURIComponent(f.name)}">${f.name}</a></li>`);
res.send(`<!DOCTYPE html>
<html>
<head>
<title>File list</title>
</head>
<body>
<ul>
${links.join("\n\t\t")}
</ul>
</body>`);
});
});
app.listen(4567, () => console.log("http://127.0.0.1:4567/")); How does
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello, I've recently found myself doing a project where I needed to server .mp3 files. Which I managed to do by simply serving that folder as with
express.static
and everything's good 👍However, I'm interested in how Express handles that under the hood? And why don't I see any network when I open the mp3 file url?
as opposed to normal images
Beta Was this translation helpful? Give feedback.
All reactions