const express = require('express') var fs = require("fs"); var syncRequest = require("sync-request"); const app = express() const port = 5243 app.get('/', (req, res) => { res.send('Hello!!!') }) app.post("/track", function (req, res) { var updateFile = function (response, body, path) { if (body.status == 2) { var file = syncRequest("GET", body.url); fs.writeFileSync(path, file.getBody()); } response.write("{\"error\":0}"); response.end(); } var readbody = function (request, response, path) { var content = ""; request.on("data", function (data) { content += data; }); request.on("end", function () { var body = JSON.parse(content); updateFile(response, body, path); }); } if (req.body || req.body.hasOwnProperty("status")) { updateFile(res, req.body, req.query.path); } else { readbody(req, res, req.query.path) } }); app.listen(port, () => { console.log(`Example app listening on port ${port}`) })