How to add data from an input field in the browser to my array websites[name], and then display it in a html paragraph?
server.js
import express from "express"
import { websites } from "./websites.js"
import { fileURLToPath } from 'url';
import { dirname } from 'path';
import * as http from 'http'
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const server = express();
server.use(express.json());
server.get("/last", (req,res) =>{
res.sendFile("index.html", {root: __dirname});
})
server.post("/last", (req,res) => {
var DataG = req.body.name;
http.get({host: DataG}, function(response){
console.log(response.statusCode)
if(response.statusCode < 400)
console.log("server is up")
else{
console.log("server is down")
}
});
res.send("Request processed");
})
index.html
<body>
<center>
<input class="text" placeholder="input website">
<button class="subBtn">Submit</button><br><br>
<div id="pisun"></div>
</center>
<script>
let pisun = document.getElementById("pisun")
let pisunchik1 = document.createElement("p").textContent = "nothing"
let websiteName = document.querySelector(".text")
let button = document.querySelector(".subBtn")
if(button)
{
button.addEventListener("click", () =>{
let obj = {
name:websiteName.value
};
fetch("http://localhost:3000/last",{
method:"POST",
headers:{
"Content-type":"application/json"
},
body:JSON.stringify(obj)
})
})
}
</script>
</body>
websites.js ("db")
export const websites = [
{name:"google", enable: true},
{name:"bing", enable: true},
];
postrequest before thehttp.getinside is finished. 2. What do you want to display and where?