illcrx
illcrx

Reputation: 814

express deprecated res.redirect(url, status): Use res.redirect(status, url)

writing my express app I came across this error and am unsure what to do? Using express 4.14 and I am not sure what to do, its looking for a status its saying however I am not giving it a status currently. Event looking at their docs they dont give a status with their example routes.

express deprecated res.redirect(url, status): Use res.redirect(status, url)

Here is my code:

router.post("/event",  isLoggedIn, function (req,res){
// get data from form and add to events array
var title = req.body.title;
var date =  req.body.date;
var description = req.body.description;
var venue = req.body.venue;
var photo = req.body.photo;
var category = req.body.category;
//get user data to save to the user
var owner = {
    id: req.user._id,
    username: req.user.username
}

var newEvent = {category: category, title: title, date: date, description: description, venue: venue, photos:{link: photo,date: date}, owner: owner};
Event.create(newEvent, function(err, event){
    if(err){
        console.log(err)
    } else {
        //This takes the event owner ID and saves it into the model
        event.owner.id = req.user._id;
        //This takes the event username and saves it into the model
        event.owner.username = req.user.username;
        event.save();
        console.log(event);
        res.render('events',{events: event});        }
})

})

Upvotes: 0

Views: 3921

Answers (2)

Manish
Manish

Reputation: 1

My problem is resolved by updating the atom package you can check if there is any update in your editor package.

Upvotes: 0

Alessio Dionisi
Alessio Dionisi

Reputation: 81

In my projects I have always done it this way:

function(req, res) {
    res.status(301).redirect('http://google.com')
}

Upvotes: 1

Related Questions