Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to create a dir in Node like "mkdir -p" does?

Tags:

node.js

mkdir

Is it possible to use the fs API to create a directory and all necessary subdirectories like the -p parameter does when using the mkdir command?

like image 970
Pablo Avatar asked Sep 10 '25 12:09

Pablo


2 Answers

Use fs.mkdirSync with the recursive: true option:

fs.mkdirSync('/tmp/a/apple', { recursive: true });
like image 135
Dániel Mari Avatar answered Sep 13 '25 02:09

Dániel Mari


You can either write your own version or use a module like mkdirp

like image 20
simon-p-r Avatar answered Sep 13 '25 02:09

simon-p-r