I want to check if the path is a file or a directory. If it's a directory then Log the directory and file separately. Later I want to send them as json object.
const testFolder = './data/';
fs.readdir(testFolder, (err, files) => {
  files.forEach(file => {
    console.log(`FILES: ${file}`);
  })});
Edit: If I try to this
fs.readdir(testFolder, (err, files) => {
  files.forEach(file => {
    if (fs.statSync(file).isDirectory()) {
    console.log(`DIR: ${file}`);
  } else {
    console.log(`FILE: ${file}`)
  }
  })}); 
I get this error:
nodejs binding.lstat(pathModule._makeLong(path))
Update: Found the solution. I had to add testFolder + file like this :
if (fs.statSync(testFolder + file).isDirectory()) {
 
     
    