1<!-- Nunjucks to loop the array and show each file in a list -->
2<ul>
3 {% for file in fileList %}
4 <li>{{ file }}</li>
5 {% endfor %}
6</ul>
1const directoryPath = './path/to/dir/';
2
3// loop files in directory and push to an array and pass to rendered screen
4router.get('/slug', (req, res) => {
5 let fileList = [];
6 fs.readdir(directoryPath, (err, file) => {
7 if (err) {
8 return console.log('Unable to scan directory: ' + err);
9 }
10 file.forEach((file) => {
11 fileList.push(file);
12 });
13 // Passing the array to the rendered screen
14 res.render('rendered/screen', {fileList});
15 });
16});