I just created my first app with node.js and express. And I only want to print out current url, so I add these lines:
app.use('/test', function(request, response){
console.log('current url is '+request.url);
response.end();
})
Now when I run on browser at localhost:3000/test in will print me: current url is /
Can someone explain it to me?
i had the same issue and the solution was so obvious...
I had a "express rule" like:
app.all('*', function(req, res) {
res.redirect('/')
})
And that redirect me automaticly to "/" route so it doesn't work...
In your case, I think the problem comes from your keywork "use" used with express. Try this:
app.get('/test', function(request, response){
console.log('current url is '+request.url);
response.end();
})
Try for this:
var Url = req.protocol + '://' + req.get('host') + req.originalUrl;
Reference in StackOverflow: How to get full URL in Express.js
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With