Shayan Khan Shayan Khan - 1 year ago 51
Node.js Question

Express router "res" object has to take me to other pages

See the example below:

var apiRouter = express.Router();'/api/postAgree', function(req, res, next){
{profileID: req.session.facebookProfileId},
{$push:{postsAgreed: req.query.postID}},
{safe: true, upsert: true},

function(err, model) {
if (err){

Now, the MongoDB operation is already done and I want to stay on the same page.

Will I be doing this:

res.render('theSamePageIamOn', {foo:bar});

I know this works but it seems like it is a very inefficient way of doing it.

So my question really is: If I have a button on a page which makes an API call but I want to stay on the same page, how will I do that? The res.(options) function sort of is made like it has to take me to other pages

Answer Source

Thanks to @robertklep and @GiladArtzi - it should be an AJAX call and the response should be in the form of:


Then the response can be handled by the frontend using other tools like: Angular