const targetFolder = './app/images/';
const fs = require('fs');
const jsonfile = require('jsonfile');
let json = [];
fs.readdir(targetFolder , (err, files) => {
files.forEach(file => {
json.push({file.split('.')[0]})
});
})
jsonfile.writeFile(targetFolder , json);
It is strange when json.push doesn't work here. When I do console like
console.log(file.split('.')[0]) I can see the list of files in my terminal.