Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
124
rated 0 times [  130] [ 6]  / answers: 1 / hits: 29897  / 10 Years ago, tue, november 18, 2014, 12:00:00

How can I parse a url?



site.com:8080/someFile.txt?attr=100


or



site.com:8080/someFile.txt/?attr=100


I need to get someFile.txt, where is a file name I set by myself as the format (txt or some other).



UPDATE



I tried



var path = url.parse(req.url).path;


But I still cannot get the path (someFile.txt).


More From » node.js

 Answers
45

Something like this..



var url = require(url);
var path = require(path);
var parsed = url.parse(http://example.com:8080/test/someFile.txt/?attr=100);
console.log(path.basename(parsed.pathname));

[#68772] Friday, November 14, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kamronr

Total Points: 749
Total Questions: 110
Total Answers: 122

Location: Dominica
Member since Sat, Nov 5, 2022
2 Years ago
kamronr questions
Mon, Dec 21, 20, 00:00, 3 Years ago
Fri, Oct 16, 20, 00:00, 4 Years ago
Sat, Oct 3, 20, 00:00, 4 Years ago
Sun, Jul 28, 19, 00:00, 5 Years ago
;