Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
ExpressJS middleware. Send response containing data. Format in JSON
, XML
, csv
, xlsx
, html
, and text
.
$ npm install sendme
var sendme = require('sendme');
app.use(sendme(config)); // Attaches sendme(data) to res.
app.use(function(req, res) {
var json;
// Do work.
res.sendme(json);
});
config
(optional) is a JSON object containing formatting configurations. The config
is passed to the delimit()
function in tabular-json. Pass format-specific options using a sub-object (e.g. as {xlsx: {includeHeaders: false}}
), and non-specific options to the base config
object.
var config = {
includeHeaders: false,
sort: ['id'],
txt: {
separator: ';',
stringWrap: '"'
}
};
See tabular-json for more details on config options
sendme will send the response in various formats. Either specify a content type using the Accept
header, or append a format extension to the end of the req.path
. A format extension will always override the Accept
header.
.json
- Content-Types: application/json
application/json
is the primary response type..xml
- Content-Types: application/xml
, text/xml
.xlsx
- Content-Types: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
.csv
- Content-Types: application/csv
.html
- Content-Types: text/html
.txt
- Content-Types: text/plain
Specify a format in the url path:
GET /foos/1.xml HTTP/1.1
Host: example.com
var data = {
id: 1,
type: 'widget'
};
res.sendme(data);
Response:
HTTP/1.0 200 OK
Content-Type: text/xml
<?xml version="1.0" encoding="UTF-8" ?>
<data>
<id>1</id>
<type>widget</type>
</data>
Also, specify a format in the Accept
parameter:
GET /foos HTTP/1.1
Host: example.com
Accept: application/csv
Response:
HTTP/1.0 200 OK
Content-Type: application/csv
"id","type"
1,"widget"
2,"gadget"
FAQs
Express middleware used to convert json and res.send in multiple formats
The npm package sendme receives a total of 0 weekly downloads. As such, sendme popularity was classified as not popular.
We found that sendme demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.