Kingston_Pendrive/Suli/13.b/Frontend/Javascript/2024. 11. 18/server.js

36 lines
925 B
JavaScript
Raw Normal View History

2024-11-19 18:04:02 +00:00
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) => {
2024-11-20 08:20:45 +00:00
let adat = JSON.parse(data)
adat.push(req.body)
2024-11-19 18:04:02 +00:00
2024-11-20 08:20:45 +00:00
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!");
}
})
2024-11-19 18:04:02 +00:00
})
})
app.listen(3000)