Files
30-seconds-of-code/snippets/createDirIfNotExists.md
Angelos Chalaris 611729214a Snippet format update
To match the starter (for the migration)
2019-08-13 10:29:12 +03:00

409 B

title, tags
title tags
createDirIfNotExists node,beginner

Creates a directory, if it does not exist.

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

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