-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
50 lines (35 loc) · 1.09 KB
/
index.js
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// fs.writeFile('./sampleForWriteFile.txt','Hai we created a new file','utf-8',(error)=>{
// if(error)
// console.log(error)
// else
// console.log('File created Successfully')
// })
// fs.writeFileSync('./sampleSync.txt','Next line is working?','utf-8')
// let syncdata = fs.readFileSync('./sampleSync.txt','utf-8')
// console.log(syncdata)
// fs.readFile('./sample.txt','utf-8',(error, data)=>{
// if(error){
// console.log(error)
// }
// else{
// console.log(data)
// }
// })
// let data = fs.readFileSync('./sample.txt','utf-8')
// console.log('sync',data)
const fs = require('fs')
const http = require('http')
let time = new Date().toLocaleString()
const server = http.createServer((req,res)=>{
try {
fs.writeFileSync('./date.txt',`${time}`,'utf-8')
let data = fs.readFileSync('./date.txt','utf-8')
res.writeHead(200,{
"content-type":"text/html"
})
res.end(`${data}`)
} catch (error) {
console.log(error)
}
})
server.listen(8000,()=>console.log("server is lisning port 8000"))