server.js
var express = require('express')
var app = express()
function reid() {
var fs = require('fs')
fs.mkdirSync('New')
}
app.get('/', function (req, res) {
res.sendFile(__dirname + '/index.html')
})
app.get('/createDirectory', function (req, res) {
try {
reid()
res.send(JSON.stringify({ created: 'success' }))
} catch (erorr) {
res.send(JSON.stringify({ created: 'failed' }))
}
})
app.listen(4000, function () {
console.log('started at http://localhost:4000')
})
index.html
<html>
<head>
<script>
document.addEventListener('DOMContentLoaded', function () {
document.getElementById('createDirectory').addEventListener('click', function(e) {
fetch('/createDirectory').then(r => r.json()).then(r => {
alert(r.created)
})
})
})
</script>
</head>
<body>
<h1>Expressed</h1>
<hr/>
<div id="status"></div>
<hr/>
<button id="createDirectory">Создать папку</button>
</body>
</html>
node server.js && open
http://localhost:4000