NodeJS + ExpressJS: Strip out port from req.headers.host


/ Published in: JavaScript
Save to your folder(s)

I doubt anyone will ever need this but just in case. I had a scenario where I needed to deliver the hostname (without the port) through an .ejs variable. The hostname comes from the request header so that's easy to find and I simply used a .match with a ternary conditional to keep things clean.

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.