Advertisement
Guest User

Untitled

a guest
Jun 27th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. ...
  2. app.post('/testapi', function (req, res) {
  3.  
  4. request({
  5. "url": 'https://webservice.com',
  6. "method": "POST",
  7. "body" :req.body
  8. },
  9. function(err, response, body){
  10. if (err) {
  11. res.send(err);
  12. } else {
  13. res.send(body);
  14. logSomeData(req.body);
  15. }
  16. });
  17. });
  18.  
  19. function logSomeData(body) {
  20. var currYear = new Date().getFullYear(),
  21. currMonth = new Date().getMonth(),
  22. fileName = __dirname + '/logs/' + currYear + '_' + currMonth + '.json';
  23.  
  24. parseString(body, function (err, result) {
  25. jsonfile.readFile(fileName, function(err, obj) {
  26.  
  27. var logData = {test : "test"};
  28.  
  29. obj.push(logData);
  30.  
  31. jsonfile.writeFile(fileName, obj, {spaces: 2}, function(err) {
  32. console.error(err)
  33. });
  34. });
  35. });
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement