Answers for "node js create directiories and file"

6

nodejs make directory

var fs = require('fs');
var dir = './tmp';
if (!fs.existsSync(dir)){
    fs.mkdirSync(dir);
}

// or if complains about existence and nesting doesn't matter:

var shell = require('shelljs');
shell.mkdir('-p', 'root/parent/tmp');
Posted by: Guest on March-30-2020
0

javascript fs write file with folder

var path = require('path'),
    fs = require('fs');

function ensureDirectoryExistence(filePath) {
  var dirname = path.dirname(filePath);
  if (fs.existsSync(dirname)) {
    return true;
  }
  ensureDirectoryExistence(dirname);
  fs.mkdirSync(dirname);
}
Posted by: Guest on October-26-2020

Code answers related to "node js create directiories and file"

Code answers related to "Javascript"

Browse Popular Code Answers by Language