Friday 19 May 2017

NodeJS+Express - How To Re-route/Redirect a JSON Object So I am able to Use the data as a Client?

So I am new to NodeJS+Express. I think the question is really trivial for most of you. Here we go.

So, I have this simple webhook project that is simply posting some JSON data from a beacon. So far so good, all is working fine.

However, I am trying to actually get the logged JSON payload to re-route or redirect to a different path like:

/mydata

so that I can access that JSON payload by going to a URL in the browser and fetch it.

Here's the request handler where all is being done:

router.get('/', function (req, res) {
       res.json({
       token: secrets.validator
     });
 });

 router.post('/', function (req, res) {


 console.log('-----POSTED-MESSAGE----');
 console.log(req.body);
 /*
    Write code here to forward the req.body to a db or another url 
    instead of console!

  */
  var myJson = req.body; //how do I actually get this to show in a 
  different url so that I can see the JSON data and parse it as a Client?


  console.log('---------------------------------');

    res.json({
        token: secrets.validator
     });


 });

Like I mentioned earlier, all is good - the req.body logs the JSON data fine; however I need to push it "somewhere" where I can actually do a GET and get that data.

I hope this makes sense.

Any help is highly appreciated.

Thank you.



via ito

No comments:

Post a Comment