DEV Community

Cover image for Node.js IsDirectory
Adam K Dean
Adam K Dean

Posted on

Node.js IsDirectory

Here's a useful snippet for checking if a path is a directory in Node.js, this obviously requires('fs').

fs.lstatSync(path_string).isDirectory()

Also available to you:

fs.lstatSync(path_string).isFile()
fs.lstatSync(path_string).isDirectory()
fs.lstatSync(path_string).isBlockDevice()
fs.lstatSync(path_string).isCharacterDevice()
fs.lstatSync(path_string).isSymbolicLink()
fs.lstatSync(path_string).isFIFO()
fs.lstatSync(path_string).isSocket()

Top comments (0)