0

Hey guys just started with nodejs and express so i came up with the situation where i want to send my data to my GET req from my POST req.Here is the code below for you to understand

app.post('/run-time',(req,res)=>{
    const stoptime=req.body.stop
    const plannedtime=req.body.planned
    const runtime=plannedtime-stoptime
    res.redirect('/run-time')
})

this is my POST req where i fetched the values from the form and then calculated the 'runtime' now then i have to redirect to specific GET route

app.get('/run-time',(req,res)=>{

})

so what i want is send the 'runtime' variable calulated in my POST req to my GET req here ..how can i do this ?

2

1 Answer 1

1

I've never been use that way But I think you can use querystring querystring can contains data in url.

app.post('/run-time',(req,res)=>{
    const stoptime=req.body.stop
    const plannedtime=req.body.planned
    const runtime=plannedtime-stoptime 
    res.redirect(`/run-time?runtime={runtime}`);
})

app.get('/run-time',(req,res)=>{
    var runtime = req.query.runtime;
    //~ 
})

I think that way can be your solution. But you have to change your code because It is not used like this. Maybe many solution is.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.