Node.js create folder or use existing

后端 未结 14 1429
暖寄归人
暖寄归人 2020-12-04 06:43

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

相关标签:
14条回答
  • 2020-12-04 07:47

    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
    
    });
    
    0 讨论(0)
  • 2020-12-04 07:49

    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.

    0 讨论(0)
提交回复
热议问题