ensureDirSync(dir)

Ensures that the directory exists. If the directory structure does not exist, it is created. Like mkdir -p.

Aliases: mkdirsSync(), mkdirpSync()

  • dir <String>

Example:

  1. const fs = require('fs-extra')
  2. const dir = '/tmp/this/path/does/not/exist'
  3. fs.ensureDirSync(dir)
  4. // dir has now been created, including the directory it is to be placed in