-
Notifications
You must be signed in to change notification settings - Fork 0
/
myapp.js
29 lines (26 loc) · 885 Bytes
/
myapp.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
var express=require("express");
var bodyParser = require('body-parser');
var app=express();
var port=process.env.PORT||8000;
var fs=require("fs");
app.listen(port);
app.use(bodyParser.json()); // support json encoded bodies
app.use(bodyParser.urlencoded({ extended: true })); // support encoded bodies
app.post('/', function(req, res) {
var x_co = req.body.x;
var y_co = req.body.y;
var z_co = req.body.z;
fs.appendFile('data.txt', x_co+" "+y_co+" "+z_co+"\n", encoding='utf8', function (err) {
if (err) console.log(err);
});
res.send(x_co + ' ' + y_co + ' ' + z_co);
console.log(x_co + ' ' + y_co + ' ' + z_co);
});
app.get('/data.txt',function(req,res){
fs.readFile('data.txt','utf8',function(err,contents){
res.send(contents);
var filePath = "data.txt";
fs.unlink(filePath);
});
});
console.log("Server is started");