I'm new to express and often see the code like this:
app.once('mount',function onmount(parent){
parent._router.stack.pop();
});
Not sure what is _router
and why they pop
it? Any reasons behind it?
The mount event occurs when a sub-app is registered with a parent app. The parent
argument is the parent app object.
parent._router
is the router associated with that parent app object.
parent._router.stack
is the array of routes registered with that route.
parent._router.stack.pop()
is removing the last registered route from that router.
There isn't enough context here for us to know why that last route is being removed. It's possible they are trying to remove the 404 error route (just a guess).
FYI, this direct manipulation of private instance variables is not documented behavior.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With