Node.js create folder or use existing

后端 未结 14 1461
暖寄归人
暖寄归人 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条回答
  •  猫巷女王i
    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
    
    });
    

提交回复
热议问题