'How do I redirect to a different page from this function nodejs
I need help redirecting after I submit this order. Basically everything is working but after the order is saved I can't figure out how to redirect the view. I would like to just redirect to the index which is at "/" but everything I've tried doesn't work. Any tips would be greatly appreciated.
app.post('/postOrder/:id', function(req, res, next){
var customerInfo = req.body.info;
var packageInfo = req.body.items.items;
var storeID = req.params['id']
let ts = Date.now();
let date_ob = new Date(ts);
let date = date_ob.getDate();
let month = date_ob.getMonth() + 1;
let year = date_ob.getFullYear();
let yourOrder = []
packageInfo.forEach((package) => cusOrder(package.product, package.qty));
function cusOrder(product, qty){
let order = {product: product, qty: qty}
yourOrder.push(order);
}
console.log(yourOrder);
const order = {
package: yourOrder,
storenum: storeID,
date: year+"/"+month+"/"+date,
first: customerInfo[0].fname,
last: customerInfo[1].lname,
address: customerInfo[2].address,
city: customerInfo[3].city,
state: customerInfo[4].state,
zipcode: customerInfo[5].zip
}
Orders(order).save()
}
);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
