Nodejs page not redirecting after POST
<p>My problem is similar enough to <a href="https://stackoverflow.com/questions/9107226/how-to-end-an-express-js-node-post-response">this</a> but also different and the answers aren't working for me.</p>

<p>I have a form to post and I need to display a message on the page whether it entered the data to the database successfully or not.  So I have:</p>

<pre><code>app.post('/add_new', upload.single('image'), function add_new(req, res, err)

{
   var image = req.body.image; 
   // do some checks and try to insert
    if (err){
        res.render('page_name',{images:images, message:'There was an error'})
    }
    else{
     images.push(image);
     res.render('page_name',{images:images, message: 'Success'})}
    }
}
</code></pre>

<p>The error/success messages are handled on the client side.</p>

<p>My problem is that it doesn't actually complete the post.  It renders the page with the error/success message correctly but the URL looks like 'my_site.com/add_new', and if the user refreshes the page for any reason, it sends that 'form resubmission' alert, which causes problems.  I need it to go back to 'my_site.com' and display the message.</p>

<p>I have found that doing </p>

<pre><code>res.redirect('back') 
</code></pre>

<p>returns to the correct page but obviously doesn't display the message.
I have noticed a few answers recommending </p>

<pre><code>res.end('Success') 
</code></pre>

<p>but that just displays a white page with the word 'Success' - I don't know how anyone thinks that's an acceptable solution!</p>

<p><strong>EDIT:</strong>
Following Vinay's answer, my code now reads like:</p>

<pre><code>app.post('/add_new', upload.single('image'), function add_new(req, res, err)

{
   var image = req.body.image; 
   // do some checks and try to insert
    if (err){
        req.session.msg='error adding';
        res.redirect('page_name');
    }
    else{
     images.push(image);
     req.session.msg='success';
     res.redirect('page_name');
    }
}
</code></pre>

<p>and this to get the page:</p>

<pre><code>app.get('/page_name', is_logged_in, function(req, res) {
    if(req.session.msg){
        res.render('page_name', {images: images, user:req.user, message: req.session.msg});
        setTimeout(req.session.msg="", 4000);
    }
    else{
        res.render('page_name', {images: images, user:req.user, message:''});
    }
});
</code></pre>

<p>But I am still finding that the error message persists when the page is refreshed.  Have I made a mistake?</p>