I decided to create a custom module that exports two key functions: pathRaw
and pathFor
.
The pathRaw
function generates a path that can be used with the express routing system. For example:
pathRaw('user.photo.upload');
would output '/users/:userid/photos/upload'
. It's worth noting that I've incorporated mongoose's pluralization functionality here.
On the other hand, the pathFor
function takes the raw path from pathRaw
and substitutes the specified ids. For instance:
pathFor('user.task.list', {userid: '123'});
would render '/users/123/tasks'
. Any additional values are transformed into query parameters automatically.
I have also included features such as path overrides in this module. Once I've tested it more thoroughly, I plan to make it available on GitHub.