DEV Community

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

Posted on

1

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)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more