Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to check if a folder exist if not then create nodejs

//For individual dirs:
var {existsSync, mkdirSync} = require('fs');
var dir = './tmp';

if (!existsSync(dir)){
    mkdirSync(dir);
}

//For nested dirs:
var {existsSync, mkdirSync} = require('fs');
var dir = './tmp/but/then/nested';

if (!existsSync(dir)){
    mkdirSync(dir, { recursive: true });
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #check #folder #exist #create #nodejs
ADD COMMENT
Topic
Name
7+4 =