Parse application/x-www-form-urlencoded forms
HTML form submissions
Express.js · Function
express.urlencoded() creates built-in middleware for parsing URL-encoded request bodies. Matching parsed data is made available through req.body.
Calling express.urlencoded(options) creates middleware that examines incoming requests whose Content-Type matches the configured type, parses URL-encoded request bodies, and places the result on req.body. It accepts UTF-8 input and automatically inflates gzip or deflate content.
express.urlencoded([options])| Name | Type | Description |
|---|---|---|
options | Object | undefined | Options controlling URL-encoded body parsing, or undefined to use defaults. |
options.extended | Boolean | Chooses querystring when false or qs when true; true is the documented Express 4.x default. |
options.inflate | Boolean | Controls whether compressed request bodies are inflated; documented default is true. |
options.limit | Number | String | Maximum request-body size; a number represents bytes, while a string is parsed as a size. |
options.type | String | Function | Controls which Content-Type is parsed. |
Middleware that parses matching URL-encoded request bodies and populates req.body.
const express = require('express');
const app = express();
app.use(express.urlencoded({ extended: true }));
app.post('/profile', (req, res) => {
res.json(req.body);
});
app.listen(3000);Parses matching URL-encoded form submissions and returns the parsed data from req.body.
HTML form submissions
Nested form data
Compressed requests
It returns middleware that parses URL-encoded request bodies and populates req.body. Parsing is limited to requests whose Content-Type matches the configured type option.
Follow-up: How would you support nested form objects? Set extended to true so the qs library can represent rich objects and arrays.
With extended false, parsing uses the querystring library. With extended true, it uses qs, which supports richer object and array structures; the Express 4.x documentation lists true as the default.
Follow-up: What should be checked when migrating to Express 5? Express 5 changes the default extended value to false, so applications depending on extended parsing should set it explicitly to true.
The middleware accepts only UTF-8 request bodies and automatically handles gzip and deflate encodings. It only processes URL-encoded payloads when the request Content-Type matches the selected type.
Follow-up: Where does application code read the parsed result? After the middleware runs, handlers read the parsed key-value data through req.body.
express.json()express.raw()express.text()req.bodybody-parser