-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathform.js
More file actions
28 lines (23 loc) · 822 Bytes
/
Copy pathform.js
File metadata and controls
28 lines (23 loc) · 822 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
//imprting http module to create a server and fs module to read the html file//
const http=require('http');
const fs=require('fs');
const server=http.createServer((req,res)=>{
fs.readFile('html/form.html','utf-8',(err,data)=>{
if(err){
res.writeHead(500,{'content-type':'text/plain'});
res.end('Error occurred while reading the file');
return;
}
res.writeHead(200,{'content-type':'text/html'});
if(req.url==='/'){
res.writeHead(200,{'content-type':'text/html'});
res.write(data)
}
else if(req.url=='/submit'){
res.write('<h1>data is submitted</h1>');
res.write('<h1>data is submitted</h1>');
}
res.end();
});
});
server.listen(2000);