Kebab file names
This commit is contained in:
23
snippets/create-dir-if-not-exists.md
Normal file
23
snippets/create-dir-if-not-exists.md
Normal file
@ -0,0 +1,23 @@
|
||||
---
|
||||
title: Create directory if not exists
|
||||
tags: node
|
||||
cover: sunrise-over-city
|
||||
firstSeen: 2018-12-12T19:25:16+02:00
|
||||
lastUpdated: 2020-10-22T20:23:47+03:00
|
||||
---
|
||||
|
||||
Creates a directory, if it does not exist.
|
||||
|
||||
- Use `fs.existsSync()` to check if the directory exists, `fs.mkdirSync()` to create it.
|
||||
|
||||
```js
|
||||
const fs = require('fs');
|
||||
|
||||
const createDirIfNotExists = dir =>
|
||||
!fs.existsSync(dir) ? fs.mkdirSync(dir) : undefined;
|
||||
```
|
||||
|
||||
```js
|
||||
createDirIfNotExists('test');
|
||||
// creates the directory 'test', if it doesn't exist
|
||||
```
|
||||
Reference in New Issue
Block a user