title | tags | author_title | author_url | author_image_url | description | image |
---|---|---|---|---|---|---|
createDirIfNotExistsSync |
node,beginner |
Deepak Vishwakarma |
Implementation of "createDirIfNotExistsSync" in typescript, javascript and deno. |
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