node.js create file in directory code example
Example 1: how to create a folder using fs in node js
//Include fs module
const fs = require('fs');
const dir = './dir'
fs.mkdir(dir);
Example 2: create directory when writing to file in nodejs
fs.mkdir now accepts a { recursive: true } option like so:
// Creates /tmp/a/apple, regardless of whether `/tmp` and /tmp/a exist.
fs.mkdir('/tmp/a/apple', { recursive: true }, (err) => {
if (err) throw err;
});