Get folder contents in json

Hi, is there any way to get the contents of a folder in json?

1 Like

Hi, Panduso, welcome!

In Node.js (server side JavaScript) you can do this using the fs plugin that’s built in:

const fs = require('fs');

// directory path
const dir = './files/';

try {
  const files = fs.readdirSync(dir);
  console.log(files); // The object itself
  const filesJson = JSON.stringify(files);
  console.log(filesJson); // As a JSON string
} catch (err) {

Further reading:

Hope it helps :slight_smile:

1 Like

Thanks, i’ll try it out!

1 Like