-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
44 lines (37 loc) · 944 Bytes
/
app.js
File metadata and controls
44 lines (37 loc) · 944 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
const express = require('express');
const app = express();
const fs = require('file-system');
const bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
app.use(express.static(__dirname + '/'));
app.get("/",function(req,res){
fs.readFile(__dirname + '/index.html',function(err,data){
if(!err){
res.write(data);
}
res.end();
})
})
app.post("/status/new",function(req,res){
let status = JSON.stringify({"name":req['body']['name'],"status": req['body']['status']});
fs.writeFile(__dirname + "/posts.json",status,function(err){
if(err)console.log(err);
})
})
app.get("/status",function(req,res){
fs.readFile(__dirname + '/posts.json',function(err,data){
if(!err){
res.send(JSON.parse(data));
}else{
console.log(err);
}
})
})
app.listen(3000,function(err){
if(err){
console.log("error:",err);
}else{
console.log("listening on port 3000");
}
})