Skip to content

Instantly share code, notes, and snippets.

@stevenbeales
Created February 12, 2019 02:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevenbeales/08ee86ddefa30ac413c776534fdb5176 to your computer and use it in GitHub Desktop.
Save stevenbeales/08ee86ddefa30ac413c776534fdb5176 to your computer and use it in GitHub Desktop.
const fs = require('fs');
const createDirIfNotExists = dir => (!fs.existsSync(dir) ? fs.mkdirSync(dir) : undefined);
createDirIfNotExists('test'); // creates the directory 'test', if it doesn't exist
Creates a directory, if it does not exist.
Use fs.existsSync() to check if the directory exists, fs.mkdirSync() to create it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment