Learning approach:
- First, create some "mock" CSV, save it somewhere on server and use this: Download a file from NodeJS Server using Express
Assure that you properly download it.
After that, use this: Write to a CSV in Node.js
With this one, you can find out how to make CSV from any data.
Make now, that you prepare your data from SQL and really save .csv file on server (second link) and then create its download (first link).
Assure that this properly work.
Now, you have solution which works what you need, but it is not nice, it has extra step (saving file to server to download it). Check this: Express - Return binary data from distant webservice
Here it is described how can you download "binary data".
So, your final algorithm should be:
- Make SQL queries, prepare CSV data
- Get that CSV data as "binary"
- Perform download through express, of that binary data