40 likes | 57 Views
You must have tried with downloading data in CSV using GET request from UI and used Node.js as backend.<br><br>How are you going to download the same data in csv using POST request from UI ? ( thereu2019s some scenario where you need to consume some data from UI and rest from backend code )<br><br>Topics covered:<br><br>1. Download CSV using GET request using node.js NPM<br><br>2. Download CSV using POST request<br><br>Download CSV using GET request<br><br>json2csv<br><br>If you are using Hapi.js Framework<br><br><br>json2csv = require('json2csv');<br><br>json2csv({data: request.payload, <br> fields: ['productId', 'extProductId', 'tenantId', <br>
E N D
AUG 2023 08 Asign menu 0 HOME INSIGHTS ABOUT US WEB PORTFOLIO MOBILE PORTFOLIO CAREERS CONTACT US BLOG Blog Home / Web Design and UI design / json2CSV in POST data using Node.js and Angular.js ANGU L AR. JS DEVEL OPM ENT SERVI CES, CU ST OM SOFT W ARE DEVEL OPM ENT COM PANY I N BANGAL ORE, M OBI L E APPL I CAT I ONS DEVEL OPM ENT , NODE JS - BACK END, NODE. JS, W EB DESI GN AND U I DESI GN json2CSV in POST data using Node.js and Angular.js CronJ, 8 years ago 1 min read ? Listen to Post You must have tried with downloading data in CSV using GET request from UI and used Node.js as backend. How are you going to download the same data in csv using POST request from UI ? ( there’s some scenario where you need to consume some data from UI and rest from backend code ) Topics covered: 1. Download CSV using GET request using node.js NPM 2. Download CSV using POST request Download CSV using GET request
If you are using Hapi.js Framework json2csv = require('json2csv'); json2csv({data: request.payload, fields: ['productId', 'extProductId', 'tenantId', 'supplierId', 'statusId', 'mfgProductId', 'mfgProductName', 'manufacturerId', 'manufacturerName'], fieldNames: ['productId', 'extProductId', 'tenantId', 'supplierId', 'statusId', 'mfgProductId', 'mfgProductName', 'manufacturerId', 'manufacturerName']}, function(err, csv) { if (err) console.log(err); return reply(csv) .header('Content-Type', 'application/octet-stream') .header('content-disposition','attachment; filename=CronjReport.csv;'); }); If you are using Express.js Framework json2csv = require('json2csv'); json2csv({data: request.payload, fields: ['productId', 'extProductId', 'tenantId', 'supplierId', 'statusId', 'mfgProductId', 'mfgProductName', 'manufacturerId', 'manufacturerName'], fieldNames: ['productId', 'extProductId', 'tenantId', 'supplierId', 'statusId', 'mfgProductId', 'mfgProductName', 'manufacturerId', 'manufacturerName']}, function(err, csv) { if (err) console.log(err); response.setHeader('Content-Type', 'application/octet-stream'); response.setHeader("Content-Disposition", 'attachment; filename=CronjReport.csv;'); response.end(csv, 'binary'); });
Download CSV using POST request You only need to handle di?erently from Angular side. $http.post('/exportProduct',searchdata) .success(function(data, status, headers, config) { var element = angular.element(''); element.attr({ href: 'data:attachment/csv;charset=utf-8,' + encodeURI(data), target: '_blank', download: 'name.csv' })[0].click(); }) .error(function(data, status, headers, config) { }); VIA SOURCE TAGS #ANGULAR.JS #CRONJ #EXPRESS.JS #HAPI.JS #HYDERABAD #NODE JS ANGU L AR. JS DEVEL OPM ENT SERVI CES, NODE JS - BACK U NCAT EGORI ZED END, NODE. JS, W EB DESI GN AND U I DESI GN Hapi ?le upload download Frameworks are a developers best friend. CronJ CronJ is a product development company which solves problems in Video analytics, IoT, Industrial automation, Manufacturing 4.0, Smart Factory, Smart City, Blockchain, Arti?cial Intelligence, Mobility Solutions and supply chain consulting. Related posts