![]() ![]() ![]() Now we can use pg module to make a connection and query data easily: const Pool = require("pg").Pool Ĭlient.query("SELECT * FROM category", (err, res) => ) Ĭonst csv = json2csvParser.parse(jsonData) įs.writeFile("bezkoder_postgresql_fs. Run the command to install the module: npm install pg. Pg module can help us to connect and get data from PostgresSQL database. We need to get all the tableâs rows and parse them into a kind of data that can be read & export to CSV file. +-+-+-Ä¡ | Node.js | JavaScript runtime environment | Ä¢ | Vue.js | JavaScript Framework for building UI | Ä£ | Angular.js | Platform for building mobile & desktop web app | Export PostgreSQL data to CSV file using fsĪssume that our PostgresSQL database has a table category like this: SELECT * FROM category.Data pasted and converted remains local on your computer. Export PostgreSQL data to CSV file using csv-writer Csvjson helps you quickly convert popular data formats to the format you need.Export PostgreSQL data to CSV file using fast-csv Navigate to the folder, where you want to create your project and execute the following commands in the terminal: npm init -y npm install csvjson -save The first command will initialize a node project without asking any questions (-y tells npm to use the default init settings).I have the naming of the fields static here, but you could use code to set the headers dynamically: for(var j=0 jhave a similar answer like but my code can be used in conjunction with Excel directly (copy and paste from Excel into a textarea). Install Install package in your package. I think, I have a better solution, this also have one issue i.e. Install npm convert-csv-to-json package Go to NPM package convert-csv-to-json. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |