[node.js] Check synchronously if file/directory exists in Node.js

const fs = require('fs');

check in the function like below,

if(fs.existsSync(<path_that_need_to_be_checked>)){
  // enter the code to excecute after the folder is there.
}
else{
  // Below code to create the folder, if its not there
  fs.mkdir('<folder_name>', cb function);
}