Horje
node list folders in directory Code Example
node list files in directory

//requiring path and fs modules
const path = require('path');
const fs = require('fs');
//joining path of directory 
const directoryPath = path.join(__dirname, 'Documents');
//passsing directoryPath and callback function
fs.readdir(directoryPath, function (err, files) {
    //handling error
    if (err) {
        return console.log('Unable to scan directory: ' + err);
    } 
    //listing all files using forEach
    files.forEach(function (file) {
        // Do whatever you want to do with the file
        console.log(file); 
    });
});
node list folders in directory
const { readdir } = require('fs')

const getDirectories = (source, callback) =>
  readdir(source, { withFileTypes: true }, (err, files) => {
    if (err) {
      callback(err)
    } else {
      callback(
        files
          .filter(dirent => dirent.isDirectory())
          .map(dirent => dirent.name)
      )
    }
  })




Javascript

Related
Cast to [ObjectId] failed for value Code Example Cast to [ObjectId] failed for value Code Example
jquery form serialized data Code Example jquery form serialized data Code Example
string reduction javascript Code Example string reduction javascript Code Example
type: mongoose.Schema.Types.ObjectId ref error Code Example type: mongoose.Schema.Types.ObjectId ref error Code Example
"message": "Route defined in OpenAPI specification but there is no defined onPUT operation." Code Example "message": "Route defined in OpenAPI specification but there is no defined onPUT operation." Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7