Posts

Showing posts with the label csv

Convert JSON to CSV with Node.js using readFileSync

Image
  I have to convert some JSON format files to CSV format to read or access them properly from MS-Excel. You are able to see I split my VS-code screen and on the left side, you can see the code that I have used for conversion, and on the right part, you will get the JSON file that we want to convert it. In the terminal below, you can view the logs as “CSV file created successfully”. So let’s go step-by-step to get the same result as mine. There are a few pre-requisites, they are as follows: a. Nodejs installed on your local machine —   https://nodejs.org/ Install packages “ json2csv”  using the following command: $  npm install json2csv npm install json2csv Additionally, you don’t need to install any packages specifically for the built-in fs (file-system) module since it is a part of Node.js and comes pre-installed with it. You can directly use it like this as shown below: const json2csv = require ( 'json2csv' ). parse ; const fs = require ( 'fs' ); The first line i...