130
BroCow
7y

Me: nodejs, how to iterate through a folder

Quora: let me tell you a story , when me and my fath.....

Stackoverflow: -1, please refer to guidelines

Yahoo answer: type command "rm -rf *"

Omegle: m 26 india ....

Cleverbot: const fs = require('fs')
const path = require('path')

function getDirectories (srcpath) {
return fs.readdirSync(srcpath)
.filter(file => fs.lstatSync(path.join(srcpath, file)).isDirectory())
}

then recurrence

me: thx cleverbot

Comments
  • 89
    NodeJS docs: this method was introduced last version; will be deprecated next version.
  • 3
    Nice tags
  • 6
    @Ashkin buuuuuurrrrrnnnnnn 🔥🔥🔥
  • 13
    Nooooooooo don't use sync in readdir, use the async method and wrap it in a promise that you then return and resolve with the filtered results. I try to only use sync when really really really needed.

    Otherwise good post 😄
  • 6
    @froot can u simplify, back in my days we used callbacks... wtf is this new promise shit
  • 4
    @BroCow that way you don't need to nest your callbacks. Your code gets much cleaner. Have a look at this: https://youtu.be/2d7s3spWAzo
  • 6
    @BroCow basically promises prevent you from having a code that look like an inception algorithm 😂😂😂😂😂😂
  • 2
    @ctwx thank you for the link Mr.Dude it cleared my doubts

    @thedev promise looks promising and all, but i like callbacks better, no overhead, and i got used to it
  • 3
    @BroCow 😄 I don't think Promises incur much overhead either. Tho callbacks still have their place. For example when your function wants to call it multiple times, like in a socket server for example
  • 1
    @ashkin jesus u r goin 2 get more ++ than for my rant ..... wtf
  • 0
Add Comment