Nodejs – Redirect url

The logic of determining a “wrong” url is specific to your application. It could be a simple file not found error or something else if you are doing a RESTful app. Once you’ve figured that out, sending a redirect is as simple as:

response.writeHead(302, {
  'Location': 'your/404/path.html'
  //add other headers here...
});
response.end();

Leave a Comment