Fetch and download under same root

So I have this route payments/transactions which fetches all the data. What I would like to do is get a CSV file without adding any new routes or query params so my route would look like payments/transactions.csv and send response based on the mime type. Im using NODEJS and EXPRESS. Thank you very much for help! :)

you can modify your route like this:

app.get("/payment/transactions(:extension?)", function...

This adds an optional parameter to your route, that you can check with req.params.extension.


A side note: I would prefer to check the req.accepts property to see which type the client requests. See http://expressjs.com/api.html#req.accepts