Node.js mkdir (can't find module mkdir)

48 Views Asked by At

I want to make with node.js a mini script which creates for me a standard Folder named "Projekt" and in the next steps make a Folder with the three Files index.html, app-js, and styles.css.

const mkdir = require('mkdir');
//const folderName = process.argv[2] || 'Project'

mkdir('Project', { recursive: true }, (err) => {
    console.log(err);
    if (err) throw err;
});

console.log("After MKDIR Statement");

/*try {
    mkdir.mkdirSync(folderName);
    mkdir.writeFileSync(`${folderName}/index.html`);
    mkdir.writeFileSync(`${folderName}/app.js`);
    mkdir.writeFileSync(`${folderName}/styles.css`);
} catch (e) {
    console.log("SOMETHING WENT WRONG!!!");
    console.log(e);
}*/

I get following response by the terminal in VS-CODE

:\\Users\\George\\Desktop\\NPM - Tutorial\> node bolerplate.js
node:internal/modules/cjs/loader:1080
throw err;
^

**Error: Cannot find module 'mkdir'**
  1. A Folder with the name 'Project'
  2. Make a Folder by a default name with three files index.html, app.js, styles.css
1

There are 1 best solutions below

2
cantdocpp On

I think you're importing it wrong.

Try to import it like this code:

const { mkdir } = require('node:fs/promises');

i get it from the official docs