How to get the Firebase path (location string without the hostname part such as
var url = require('url'); // standard Node.js 'url' module.
var location = url.parse(ref.toString()).pathname;
If you think of this outside of the context of Firebase, it becomes "How do I get just the path from a URL?" Searching for that is bound to give good results. They'll likely be similar to what you came up with now.
Another approach might be to depend on Firebase's built-in
root() method to determine the base URL.
var location = ref.toString().substring(ref.root().toString().length);