URL scheme and Export data to CSV file.【Javascript】

Tomoharu Tsutsumi
1 min readSep 25, 2021

In my application, I had to develop a CSV exporting function, and I managed to learn URL scheme simultaneously. I’m going to summarize them.

How to export data to CSV file in Javascript

Suppose that you can get CSV data from an api server, you can write codes below in order to make a CSV file.

const hiddenElement = document.createElement('a');hiddenElement.href = 'data:text/csv;charset=utf-8,' + encodeURI(res.data);hiddenElement.target = '_blank';hiddenElement.download = 'brahbrah.csv';hiddenElement.click();

Of course, there are other useful libraries, so I recommend you to use them.

URL scheme

I couldn’t understand the meaning of data: in href. It is URL scheme and the answer is below.

This data scheme means that words following data scheme are treated as contents of files.

My LinkedIn account is below! Please contact me!

https://www.linkedin.com/in/tomoharu-tsutsumi-56051a126/

--

--

Tomoharu Tsutsumi

Senior Software Engineer at two industry-leading startups ( Go | Ruby | TypeScript | JavaScript | Gin | Echo | Rails | React | Redux | Next)