コード
```
app.get('/files', (req, res) => {
  const directoryPath = path.join(__dirname, 'public/files');

  const getFiles = (dir, fileList = []) => {
    const files = fs.readdirSync(dir, { withFileTypes: true });

    files.forEach(file => {
      const filePath = path.join(dir, file.name);

      if (file.isDirectory()) {
        getFiles(filePath, fileList);
      } else {
        fileList.push(filePath);
      }
    });

    return fileList;
  };

  const fileNames = getFiles(directoryPath).map(filePath => {
    return path.relative(directoryPath, filePath);
  });

  res.render('files', { files: fileNames });
});
```
テンプレート
```
<body>
    <h1>Files in Directory and Subdirectories</h1>
    <% if (files.length) { %>
      <ul>
        <% files.forEach(file => { %>
          <li><%= file %></li>
        <% }) %>
      </ul>
    <% } %>
  </body>
```
code
```
app.get('/files', (req, res) => {
  const directoryPath = path.join(__dirname, 'public/files');

  const getFiles = (dir, fileList = []) => {
    const files = fs.readdirSync(dir, { withFileTypes: true });

    files.forEach(file => {
      const filePath = path.join(dir, file.name);

      if (file.isDirectory()) {
        getFiles(filePath, fileList);
      } else {
        fileList.push(filePath);
      }
    });

    return fileList;
  };

  const fileNames = getFiles(directoryPath).map(filePath => {
    return path.relative(directoryPath, filePath);
  });

  res.render('files', { files: fileNames });
});
```
template
```
<body>
    <h1>Files in Directory and Subdirectories</h1>
    <% if (files.length) { %>
      <ul>
        <% files.forEach(file => { %>
          <li><%= file %></li>
        <% }) %>
      </ul>
    <% } %>
  </body>
```