How to create full path with node's fs.mkdirSync?

后端 未结 22 1878
故里飘歌
故里飘歌 2020-11-29 18:03

I\'m trying to create a full path if it doesn\'t exist.

The code looks like this:

var fs = require(\'fs\');
if (!fs.existsSync(newDest)) fs.mkdirSync         


        
22条回答
  •  既然无缘
    2020-11-29 18:27

    fs-extra adds file system methods that aren't included in the native fs module. It is a drop in replacement for fs.

    Install fs-extra

    $ npm install --save fs-extra

    const fs = require("fs-extra");
    // Make sure the output directory is there.
    fs.ensureDirSync(newDest);
    

    There are sync and async options.

    https://github.com/jprichardson/node-fs-extra/blob/master/docs/ensureDir.md

提交回复
热议问题