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) {
console.log(err);
}
Further reading: https://attacomsian.com/blog/nodejs-list-directory-files
Hope it helps
1 Like
Thanks, i’ll try it out!
1 Like