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 can I use express-zip js to zip and download files?
- How do I use the Express.js documentation to create a web application?
- How do I download a zip file using Express.js?
- How do I use Yarn to add Express.js to my project?
- How do I use Express.js to upload a file to Amazon S3?
- How do I download a zip file using Express.js?
- How can I use Express.js to yield results?
- How can I use the x-forwarded-for header in Express.js?
- How can I use an ExpressJS webhook to receive data from an external source?
- What is Express.js and how is it used for software development?
See more codes...