I already have read the documentation of Node.js and, unless if I missed something, it does not tell what the parameters contain in certain operations, in particular fs.mkdi
Good way to do this is to use mkdirp module.
$ npm install mkdirp
Use it to run function that requires the directory. Callback is called after path is created or if path did already exists. Error err
is set if mkdirp failed to create directory path.
var mkdirp = require('mkdirp');
mkdirp('/tmp/some/path/foo', function(err) {
// path exists unless there was an error
});
You'd better not to count the filesystem hits while you code in Javascript, in my opinion.
However, (1) stat
& mkdir
and (2) mkdir
and check(or discard) the error code, both ways are right ways to do what you want.