Receive plain-text webhooks
Webhook endpoints that receive signed or structured text payloads.
Express.js · Function
express.text([options]) creates middleware that parses matching request bodies into strings and exposes them as req.body. It supports configurable media types, size limits, character sets, and compressed request bodies.
Calling express.text(options) creates middleware that examines the request Content-Type, parses matching bodies into strings, and places the result on req.body. It accepts Unicode text and can automatically decompress gzip or deflate bodies before parsing.
express.text([options])| Name | Type | Description |
|---|---|---|
options | Object | undefined | Optional configuration object controlling text parsing. |
options.defaultCharset | String | Fallback character set when Content-Type omits charset; default is utf-8. |
options.inflate | Boolean | Whether to handle compressed bodies; default is true. |
options.limit | Number | String | Maximum request body size; a number means bytes, while a string is parsed by the bytes library. |
options.type | String | String[] | Function | Media types to parse, or a function fn(req) returning a truthy value; default is text/plain. |
Middleware that parses matching request bodies as strings and assigns the parsed value to req.body.
const express = require('express');
const app = express();
app.use(express.text({ type: 'text/plain', limit: '10kb' }));
app.post('/echo', (req, res) => {
res.type('text/plain').send(`Received: ${req.body}`);
});
app.listen(3000);This application parses matching plain-text request bodies into req.body and echoes the resulting string.
Webhook endpoints that receive signed or structured text payloads.
Small services that echo or transform submitted text.
Endpoints accepting custom text-based media types.
express.text() returns middleware that parses matching request payloads as strings. It checks the request Content-Type against the type option and stores the parsed value in req.body.
Follow-up: How would you accept a custom media type? Pass type as a string such as application/custom, an array, or a function that receives req and returns a truthy value.
The default type is text/plain, and the default maximum body size is 100kb. The limit may be a byte count or a size string interpreted by the bytes library.
Follow-up: What happens when a request exceeds the limit? The parser rejects the request rather than producing a parsed body.
The parser accepts any Unicode encoding and automatically inflates gzip and deflate content by default. Setting inflate to false causes deflated bodies to be rejected.
Follow-up: How is a missing charset handled? defaultCharset supplies the fallback character set, defaulting to utf-8.
express.jsonexpress.rawexpress.urlencodedreq.bodybody-parser