I'm new to web development (more of a data science background with R), but I feel like this has to be possible and pretty simple, but I'm stumped. On my main index page, I want to include a list of all files included in my pages
directory as links. I want this so I don't have to set up the links manually every time -- instead, links will be created for a page when it is saved in the pages
directory.
My first thought was that there had to be a way to read the files in the directory, and from there I could build my list of links. It seems that JS can't access the server side to read the directory, though (if I'm understanding this correctly).
On this answer they suggest using Node.js with the following code:
var fs = require('fs');
var files = fs.readdirSync('/pages/');
I tried dropping that in my index page as I would javascript code, but that didn't work. If this is the solution I should pursue, where do I put the node.js code in my website directory? If it matters, I have the site hosted on GitHub.
I'd appreciate any guidance on this -- and I fully accept that I might be going about this in completely the wrong manner.