Get path of the Firebase reference

Viewed 4107

How to get the Firebase path (location string without the hostname part such as "users/user1") given the Firebase reference? I can't find in the docs and tried to search but no luck.

Now I did like this in Node.js, given Firebase reference ref:

var url = require('url'); // standard Node.js 'url' module.
var location = url.parse(ref.toString()).pathname;

Is this the correct way to do or there exist a more reliable way?

PS. I saw ref.path.o is the array containing the strings that can construct the path but I think it's not on the public API and may subject to change?

1 Answers
Related