Identifying the File System Root with Node.js
I'm doing a basic operation where I start from a given Directory, and I traverse up the filesystem until I hit the Root. On Linux/Mac, the root is obviously
/ and on Windows it can be
C:\ or another drive letter of course. My question is whether or not there is a way for Node.js to identify what the root directory of the filesystem is.
Currently, I'm resorting to simply checking the last directory against
path.normalize(dir + "/../") to see if it stops changing. Is there a
process property/method out there? Maybe a module?
Would this not work?
var path = require("path"); var os = require("os"); var root = (os.platform == "win32") ? process.cwd().split(path.sep) : "/"