Is there a chance to somehow redirect www to non-www URLs in node.js? Since there is no htaccess in node web server I am curious how to do that.
An updated version of jmar777's answer:
Using express
server.use((req, res, next) => { if (req.headers.host.startsWith('www.')) { const newHost = req.headers.host.slice(4) return res.redirect( 301, `${req.protocol}://${newHost}${req.originalUrl}`, ) } next() })