form.html:
DOCUMENT</head>
<body>
<form action="/greet" method="POST">
<input name="person">
<input>
<button type="submit">submit</button>
</form>
</body>
</html>
form.js:
const express=require(‘express’)
const app=express()
app.get(’/’,(req,res)=>{
app.send(“hello world”)
})
app.get(’/greet’,(req,res)=>{
let peson=‘Guest’
if(req.query.person){
person=req.query.person
res.send("Good Morning "+person)
}
})
app.post(’/greet’,(req,res)=>{
let peson=‘Guest’
console.log(req.body)
if(req.query.person){
person=req.query.person
res.send("Good Morning "+person)
}
})
app.get(’/form’,(req,res)=>{
res.sendFile(__dirname+’/file/form.html’)
})
app.listen(4444,()=>{
console.log(‘server started on http://localhost:4444’)
})