Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Express.JS get url path without any additional parameters

Is there any straightforward way to get URL path segment without any additional data (url parameters, css '#', etc.)

for example:

full URL: http://example.com/panel/list
path segment I want to get: /panel/list

full URL: http://example.com/panel/list?user=joe
path segment I want to get: /panel/list

full URL: http://example.com/panel/list#header
path segment I want to get: /panel/list

And any other combination of data that is not path segment of my URL

like image 387
Jakub Pastuszuk Avatar asked Mar 11 '17 13:03

Jakub Pastuszuk


1 Answers

I think you can use req.baseUrl + req.path.

And for full URL use req.originalUrl.

like image 109
rkm Avatar answered Oct 05 '22 03:10

rkm