Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
Latest commit
43 lines (37 loc) · 1.04 KB
/
Copy pathindex.js
File metadata and controls
43 lines (37 loc) · 1.04 KB
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
constexpress=require('express')
constbodyparser=require('body-parser')
constcors=require('cors')
constfs=require('fs')
vardatetime=require('node-datetime')
constapp=express();
app.use(bodyparser.json())
app.use(bodyparser.urlencoded({extended: true}))
app.get('/',function(req,res){
res.send("Cannot GET /")
})
app.post('/createNewRoom',function(req,res){
try{
if(!fs.existsSync(`transcript/${id}`)){
fs.mkdirSync(`transcript/${id}`);
}
}
catch{
res.send({success: 0});
}
res.send({success: 1});
})
app.post('/writeMessage',function(req,res){
constresult=req.body;
vardt=datetime.create();
varformatted=dt.format("d-m-Y H:M:S");
constfinalResult=`${formatted} [${result.name}]: ${result.passage}`
fs.appendFile(`transcript/${id}/${result.id}.txt`,finalResult,err=>{
if(err){
console.log(err);
}
})
res.send({success: 1});
})
app.listen(80,()=>{
console.log("Listening on port 80")
})