Reputation: 6582
If I setup a simple server using express for node.js listening on port 80
as follows:
app.get('/*', function (req, res) {
//mystuff
}
Imagine I trigger this function by going to http://www.myapp.com/first/second/third
How could I get the sections of the url between the slashes and put them in some format (array of strings). So I can get ["first", "second", "third"]
Thanks!
Upvotes: 0
Views: 171
Reputation: 5225
req.url.split('/')
Some another letters to minimal 30 symbols.
Upvotes: 1
Reputation: 4922
split them with / and split will return an array
app.get('/*', function (req, res) {
var sections = req.url.split('/');
console.log(sections);
}
Upvotes: 2