[Node.js] Create a directory and its subdirectory together

Created on November 28, 2026

Set recursive to true in the second argument of fs.mkdirSync() to create a directory and its subdirectory together. This example creates dummy_dir in the current directory and dummy_sub_dir inside it.

const fs = require('fs');

fs.mkdirSync('dummy_dir/dummy_sub_dir', { recursive: true });
Node.js