how to create multiple folders at once in node js

Solutions on MaxInterview for how to create multiple folders at once in node js by the best coders in the world

showing results for - "how to create multiple folders at once in node js"
Sarah
06 Aug 2017
1'use strict';
2
3const { mkdir } = require('fs').promises;
4
5(async function main() {
6  try {
7    const parent = '.';
8    const dirnames  = ['pdfs', 'fonts', 'err/or', 'users'];
9
10    await Promise.all(
11      dirnames.map(dirname => mkdir(`${parent}/${dirname}`).catch(console.error))
12    );
13
14    // All dirs are created here or errors reported.
15  } catch (err) {
16    console.error(err);
17  }
18})();