i'm new in node and i'm trying to add and delete routes "on the fly" in Express 4. I'm adding them using app.use(path,route) and i'm able to locate them in the app._router.stack Array but i'm not able to delete a particular router. Is it possible? I've tried with app._router.stack.splice(myRouterIndex,1) without success.
Here is my example:
for (var i = 0; i < app._router.stack.length; i++) {
if(app._router.stack[i].name=='router') {
console.log(app._router.stack[i].name);
app._router.stack.splice[i,1];
console.log(app._router.stack);
break;
}
}
The second console.log(app._router.stack) prints exactly the same as the first one.
It was a simple mistake due i'm new in Node. Thanks Ben Fortune!
The right syntax is app._router.stack.splice(i,1); due splice is a method. Doing it with brackets [] does not throw any error but simply does not work as expected.
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