express-request-csv
v1.0.1
Published
send csv when on request headers
Downloads
6
Readme
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-Type
response header. Usestext/csv
by 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/csv
query
- A key to check for field subsetting passed from the client in the query string. Defaults tofields
.