A link to the directory file.txt opens from the address localhost/files/testfolder/file.txt file.txt and a page opens with the address not localhost/files/testfolder/file.txt (as expected), but localhosy/files/file.txt . Why is this happening and how to fix it?
HTML file:
<html> <head></head> <body> <h2>Files</h2> <a href="file.txt">Open file</a> </body> </html> Node JS server code
app.get("/files/*", function(req, res) { path = req.params[0]; path = "files/" + path; try { var stats = fs.statSync(path); if (stats.isDirectory()) { fs.readdir(path, function(err, items) { res.render("files.ejs"); }); } } catch (e) { console.log("Error"); } });
/files/testfolder/file.txt- Artem Gorlachev