Home > database >  How to display events received via post in a get route
How to display events received via post in a get route

Time:09-16

I simply need to display events I'm getting in a post route in my get route.

Route that I receive requests:

app.post('/events', (request, response) => {
console.log(request.body);
response.send(request.body);

Everything working perfectly, I can see the events in console and send the response.

But, I want to display this request in a view with handlebars.

app.get('/', (request, response) => {
res.render("admin/home");

How can I do that?

EDIT:

Thanks to Nagibaba, thats how it worked:

app.post('/events', (request, response) => {
console.log(request.body);
response.send(request.body);
global.data = request.body;
});

app.get('/' (request, res) => {
var rawData = global.data;
res.render("admin/home", {rawData: rawData});
});

CodePudding user response:

You can save them in a database and display them in other routes.

  • Related