Equivalent to window.location and window.pathname in NodeJS

What is equivalent to window.location.protocol and window.location.host in NodeJS / ExpressJS?

I am trying to redirect the URL back to my site using a third-party API.

+1
source share
1 answer

NodeJS API url.format API (urlObject) returns a formatted URL string retrieved from urlObject .

 var url = require('url'); function getFormattedUrl(req) { return url.format({ protocol: req.protocol, host: req.get('host') }); } res.redirect(getFormattedUrl(req)); 
+2
source

Source: https://habr.com/ru/post/1267223/


All Articles