I am Hack Sparrow
Captain of the Internets.

How to forward non-www to www domain name and vice-versa in Node.js (Express)?

Forwarding domain names according to the requirements of 'www' is trivial in Apache using .htaccess. It's not hard either in Node.js, if you are using Express. Put the route definition of your requirement on top of all other routes in Express. This will detect the presence of 'www' and redirect the request to the domain name without 'www'. The status code of 301 means that it is a permanent redirect. If you omit the status code it doe ...