-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
50 lines (37 loc) · 957 Bytes
/
server.js
File metadata and controls
50 lines (37 loc) · 957 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const express=require('express');
const app=express();
const bodyparser = require('body-parser');
const fs=require('fs');
// app.use(express.json);
// app.use(express.urlencoded({extended: true}));
app.use(express.static(__dirname+'/public'));
app.use(bodyparser.json());
app.use(bodyparser.urlencoded({extended:true}));
app.get('/',function(req,res){
// console.log('hello');
// res.send("hi");
res.sendFile(__dirname + '/\public/\index2.html');
});
app.get('/json',function(req,res){
var content='';
fs.readFile('data.txt','utf-8',function(err,data){
if(err){
console.log(err);
}
content=data;
res.send(content);
});
});
app.post('/json',function(req,res){
var recdata=req.body.key;
console.log("post "+recdata);
fs.writeFile('data.txt',recdata,function(err){
if(err){
console.log(err);
}
res.redirect('/');
});
})
app.listen(3000, function(){
console.log(('server started'));
});