thiagomedeiros11
thiagomedeiros11

Reputation: 25

How to display events received via post in a get route

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});
});

Upvotes: 0

Views: 48

Answers (1)

Nagibaba
Nagibaba

Reputation: 5348

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

Upvotes: 1

Related Questions