1.0.1 • Published 6 years ago
express-request-csv v1.0.1
express-request-csv
CSV's should be easy to send to users that request them. Here's how we do it
const expressRequestCSV = require('express-request-csv')
const app = express()
app.use(expressRequestCSV())
app.use('/some-data', (req, res, next) => {
res.json([{a: 1}, {a: 2}])
})client side
const json = await fetch('/some-data')
const csv = await fetch('/some-data', {
headers: {
Accept: 'text/csv'
}
})Configuration Options
Parser- Don't like json2csv? Don't use it! Swap it out with your own parser.config- The configuration to pass to the new parser for the middleware instance. Uses empty object by default.header- Change the header that you react to and send inContent-Typeresponse header. Usestext/csvby default.shouldUse- An optional function to check the request and determine whether the csv parser should be used. Defaults to checking the request header fortext/csvquery- A key to check for field subsetting passed from the client in the query string. Defaults tofields.