Kingston_Pendrive/Suli/13.b/Frontend/Javascript/2024. 11. 18/server.js
2024-11-20 09:20:45 +01:00

36 lines
925 B
JavaScript

const express = require("express")
const app = express()
const path = require("path")
const fs = require("node:fs")
app.set("view engine", "ejs")
let initialPath = path.join(__dirname, "public")
app.use(express.static(initialPath));
app.use(express.json())
app.get("/", (req, res) => {
res.render("index")
})
app.post("/feltoltes", (req, res) => {
fs.readFile("F:\\Suli\\13.b\\Frontend\\Javascript\\2024. 11. 18\\public\\json/munkavallalok.json", "utf8", (err, data) => {
let adat = JSON.parse(data)
adat.push(req.body)
fs.writeFile("F:\\Suli\\13.b\\Frontend\\Javascript\\2024. 11. 18\\public\\json/munkavallalok.json", JSON.stringify(adat), (err, data) => {
if (err) {
console.log(err);
return
}
else {
console.log("Sikeres feltöltés!");
}
})
})
})
app.listen(3000)