Node.js Create Directory

The mkdirSync() method is used to create a new directory (folder) in Node.js.

Example

const fs = require("fs");

fs.mkdirSync("MyFolder");

console.log("Directory created successfully.");
        
Output:

Directory created successfully.

Explanation

  1. Import the fs module.
  2. Use mkdirSync().
  3. Give the name of the new folder.
  4. Node.js creates the folder.
← Back to Home