In express how do I redirect a user to an external url?

Michael Joseph Aubry picture Michael Joseph Aubry · Feb 5, 2015 · Viewed 84.5k times · Source

I have a payment system using node.js and braintree, when the payment is successful I want to send the user to the back end. My back end is setup elsewhere.

I have tried

res.writeHead(301,
  {Location: 'http://app.example.io'}
);
res.end();

So window.location is obviously not available. I cant think of any ways to redirect a user?

Answer

TheIronDeveloper picture TheIronDeveloper · Feb 5, 2015

You can do

res.redirect('https://app.example.io');

Express docs: https://expressjs.com/en/api.html#res.redirect