expressjsHow do I get the full URL using Express.js?
To get the full URL using Express.js, you can use the req.protocol
, req.get('host')
and req.originalUrl
properties.
Example code
const fullUrl = req.protocol + '://' + req.get('host') + req.originalUrl;
console.log(fullUrl);
Output example
https://example.com/users/1
The code above uses the following properties:
req.protocol
- the request protocol, usually either http or httpsreq.get('host')
- the hostname of the requestreq.originalUrl
- the original request URL
Helpful links
More of Expressjs
- How do I use Express.js to handle asynchronous requests?
- How do I use adm-zip with Express.js?
- How can I use Express.js to generate a zip response?
- How can I use Zipkin to trace requests in Express.js?
- How do I implement CSRF protection in an Express.js application?
- How can I set up X-Frame-Options in ExpressJS?
- How can I use Express.js and Vite together for software development?
- How do I download a zip file using Express.js?
- How do I write unit tests for ExpressJS?
- How do I render a template using Express.js?
See more codes...