I’m new to Hono, and I want to make a Hono NodeJs server that you can download files from.
in Express this code looks like this:
//configuring a static public directory of "files"
app.use(express.static(path.join(__dirname, "files")));
//if the application seeks a filename in "files", give it to it
app.get("/files/:filename", (req, res) => {
const { filename } = req.params;
res.sendFile(path.join(__dirname, "files", filename));
});
But I can’t understand how to do it. I’ve read the tutorial but still couldn’t figure it out.
There is the “serveStatic” function but the tutorial doesn’t really explain it’s parts.
should it look like this:
//setting a static (public) directory
app.use("/files/*", serveStatic({ root: "./files/*" }));
?
and how do you tell Hono to send a file if there is a get request to that static folder?
New contributor
Assaf Fogelman אסף פוגלמן is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.