0

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.

Pecners
  • 3
  • 1
  • Github does not really run node.js stuff. You need a heroku deployment. See https://stackoverflow.com/questions/15718649/how-to-publish-a-website-made-by-node-js-to-github-pages – Kasey Chang May 09 '20 at 22:48
  • If that list of pages only updates occasionally you could store it in json file that you manually update and use ajax/fetch() to read that file – charlietfl May 09 '20 at 23:01

0 Answers0