Answers for "create a folder and save a file in nodejs"

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 "create a folder and save a file in nodejs"

Code answers related to "Javascript"

Browse Popular Code Answers by Language