I am looking for a way to display the contents of a directory on an HTML page. I have the following snippet of code:
const fs = require("fs");
let directory_name = "/example";
let filenames = fs.readdirSync(directory_name);
console.log("\nFilenames in directory:");
filenames.forEach((file) => {
console.log("File:", file);
});
This will display the contents of the file in the terminal(console) but I am looking for a way to change the "console.log("File:", file)" line into a statement to send the elements to my HTML page.
Any help would be appreciated.
Using Linux btw
Use the express.js res.send
function.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.