How to check if folder exists in node js



This article will explain you how to check if folder exists in node js ,if folder is not present it will create folder .   

Below is the sample code to check if folder exists  

var fs = require('fs');
var _dirPath = "./myDirectory";
var fileName = "BusinessCard.txt";
if (fs.existsSync(_dirPath)) {
    //folder is absent
    //create folder 
    fs.mkdir(_dirPath, function (err) {
        if (err) {
            console.log(err);
        } else {
            console.log('folder created successfully');
        }
    });
} else {
    //folder is present
}	

 

Labels: how to create folder in node js, check if folder exists in node js, how to check if folder exists in nodejs



Subscribe

Receive Quality Tutorials Straight in your Inbox by submitting your Email below:

Delivered by FeedBurner

Protected by Copyscape Duplicate Content Checker