I wanted to make a website that takes an input and, using node.js for the backend, makes a folder using mkdirSync(input.value). I have the fs module installed locally and I got it to work when using javascript only, but when I try to make it from a button on a web page it doesn't work. This is my folder and file structure:
- Project folder
- node_modules
- src
- index.html
- script.js
- package-lock.json
- package.json
This is the code in the index.html and script.js files:
const fs = require("fs")
const btn = document.querySelector("#btn")
const input = document.querySelector("#in")
btn.addEventListener("click", () => {
fs.mkdirSync(`./src/${input.value}`)
})
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title> Document </title>
</head>
<body>
<input type="text" id="in">
<input type="submit" id="btn">
<script src="script.js"></script>
</body>
</html>
Is it possible to do this in the first place? I cannot use PHP since I won't be able to use a server for this project. If you have ANY other ideas please tell me, it might be of help.