How to write a large CSV file in Node.js

How to write a large CSV file in Node.js

Today, we will show you how to write a large CSV file in Node.js. Suppose you want to generate a CSV file using a dummy record in Node.js. Here we will show you a simple example to generate a large CSV file.


Use the following code to generate the large CSV file using Node.js. Here we have used the fs.createWriteStream to create a CSV file.

In the above code, we are trying to write a dummy product CSV file that contains the product name and product SKU. The CSV file will be generated at the root level of the project.

API Example

Your server.js file should look like below if you add this logic to the rest API.

Refer this article to setup REST API in node.js.
Create REST API in Node.js


Here, we have passed the number of data as a query parameter (?size=1000000). Run the following command to write 10 Lakhs records in the CSV file and the generated file will be available at the root level.

I hope you find this article helpful.
Thank you for reading. Happy Coding..!! 🙂

Demo & Source Code

GitHub Repository
If you found value in this article,
you can support us by buying me a coffee! ☕

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *