Skip to content

Latest commit

 

History

History
27 lines (21 loc) · 984 Bytes

createDirIfNotExistsSync.md

File metadata and controls

27 lines (21 loc) · 984 Bytes
title tags author_title author_url author_image_url description image
createDirIfNotExistsSync
node,beginner
Deepak Vishwakarma
Implementation of "createDirIfNotExistsSync" in typescript, javascript and deno.

TS NODE

Creates a directory, if it does not exist.

Use fs.existsSync() to check if the directory exists, fs.mkdirSync() to create it.

const { mkdirSync, existsSync } = require("fs");

const createDirIfNotExistsSync = (dir: string) =>
  !existsSync(dir) ? mkdirSync(dir) : undefined;
createDirIfNotExistsSync("test"); // creates the directory 'test', if it doesn't exist