-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttp-form-submit.js
More file actions
35 lines (30 loc) · 808 Bytes
/
http-form-submit.js
File metadata and controls
35 lines (30 loc) · 808 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const http=require('http');
const fs=require('fs');
http.createServer((req,res)=>{
let body='';
if(req.method==="GET")
{
res.writeHead(200,{'Content-Type':'text/html'});
fs.readFile('./http-form-submit.html','UTF-8',(err,data)=>{
if(err) throw err;
res.write(data);
res.end();
})
}else if(req.method==="POST")
{
req.on('data',(data)=>{
body += data;
})
req.on('end',()=>{
res.writeHead(200,{'Content-Type':'text/html'});
res.write(body,()=>{
res.end();
})
})
}else
{
res.writeHead(404,{'Content-Type':'text/plain'});
res.end('404 ERROR');
}
}).listen(4444);
console.log('its working');