How to create a directory, if it does not exist?

Sep 09, 2022
const fs = require("fs");
const createDirIfNotExists = (dir) =>
  !fs.existsSync(dir) ? fs.mkdirSync(dir) : undefined;

// Example
createDirIfNotExists("test"); // creates the directory 'test', if it doesn't exist