-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
41 lines (28 loc) · 985 Bytes
/
app.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
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const fs = require('fs');
const parseString = require('xml2js').parseString;
require('body-parser-xml')(bodyParser);
app.use(bodyParser.xml({limit: '200mb'}));
file_number = 0;
app.get('/', function(_req, res) {
res.send("Hello World! :)");
});
app.get('/sensorpush', function (_req, res) {
res.send("This is a page to take in equage data. Hey!");
});
app.post('/sensorpush', function (req, res) {
var xmlbody = req.body;
parseString(xmlbody, function(_err, _result) {
var jsonbody = JSON.stringify(xmlbody, undefined, 2)
fs.writeFile('egauge-packet' + file_number + '.txt', jsonbody, function(_err, result){
console.log('The file has been saved!');
file_number += 1;
});
})
res.send("recieved!");
});
app.listen(3000, function() {
console.log("Server is listening on port 3000 :)");
});