[Fixed] ExpressJS router with parameter empty


I’m working on my first Rest API with NodeJS using ExpressJS. It’s very simple and intuitive.
One of my routing rule is:

api.get("/api/plugin/:action", (req,res) => { ... }

If I send:


I got the error:

Cannot get /api/plugin/

Is ther a way to intercept this single case, excluding the routing without :action? I need to check req.param, and verify the action param, even if it is empty.


you can use ? in route to make your parameter optional

api.get("/api/plugin/:action?", (req,res) => { ... }

Leave a Reply

(*) Required, Your email will not be published