Read .csv with Javascript fetch
Sep 3, 2021
Commonly, we use fetch()
with method get
to read JSON from a server. But sometimes we may need to read .csv file, or retrieve csv-structure-data.
Well, it’s surprisingly easy. Just edit the header to text/csv
, and use res.text()
instead of res.json()
In case you want the server to response in .csv. Just use json2csv to parse the data.