Untitled
unknown
javascript
3 years ago
997 B
53
Indexable
//Frontend JS Code For Verification and Sending Data to Backend -
SubmitBtn.addEventListener("click", async (e) => {
if(registrationmEmail.value.match(/[^\s@]+@[^\s@]+\.[^\s@]+/gi)){
let response = await fetch("http://localhost:3000/register", {
method: "post",
headers: {
'Content-Type': 'application/json', "Access-Control-Allow-Origin": "*"
},
body: JSON.stringify({registrationmEmail})
})
let data = await response.json();
console.log(data)
}
})
//Backend Code -
const express = require("express");
const app = express();
const cors = require("cors");
app.use(express.json());
app.use(cors());
const PORT = 3000;
app.get("/", (req, res) => {
res.json({message: "hello"})
})
app.post("/register", (req, res) => {
let email = req.body.registrationmEmail;
console.log(email);
})
app.listen(PORT, () => console.log(`app is listening on ${PORT}`));Editor is loading...