Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Read only directories in node

// Promises

const { promises: { readdir } } = require('fs')

const getDirectories = async source =>
  (await readdir(source, { withFileTypes: true }))
    .filter(dirent => dirent.isDirectory())
    .map(dirent => dirent.name)
    
 // Synchronous
 const { readdirSync } = require('fs')

const getDirectories = source =>
  readdirSync(source, { withFileTypes: true })
    .filter(dirent => dirent.isDirectory())
    .map(dirent => dirent.name)
    
 // Callbacks
 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)
      )
    }
  })
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript check if string ends with 
Javascript :: how to implement toastr 
Javascript :: smallest common multiple javascript 
Javascript :: datalist example 
Javascript :: jest mongoose multiple connections 
Javascript :: Another debugger is already connected Rn @ bundle.js:10 
Javascript :: how to use hover functionality using Jquery 
Javascript :: javascript parse and validate json 
Javascript :: easy import reactjs 
Javascript :: how to create a new react native project 
Javascript :: go to nextelementsibling js 
Javascript :: mongoose nullable 
Javascript :: Add event listener to multiple buttons with the same class 
Javascript :: js ask before close 
Javascript :: react native flatlist pull to refresh 
Javascript :: vedere se radio button è cliccato js 
Javascript :: downgrade react version to 17 
Javascript :: documentready 
Javascript :: get window resolution javascript 
Javascript :: string to char array in javascript 
Javascript :: sorting disable in datatable bootstrap 
Javascript :: javascript shuffle array 
Javascript :: jquery first child 
Javascript :: disable mouse right click javascript 
Javascript :: random light color js 
Javascript :: datatables ajax reload 
Javascript :: get json from url c# 
Javascript :: cheerio load 
Javascript :: nuxt small scroll 
Javascript :: react native status bar 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =