Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Express.js · Function

express.urlencoded

express.urlencoded() creates built-in middleware for parsing URL-encoded request bodies. Matching parsed data is made available through req.body.

Since
4.16.0

How it works

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.

Syntax

express.urlencoded([options])

Parameters

NameTypeDescription
optionsObject | undefinedOptions controlling URL-encoded body parsing, or undefined to use defaults.
options.extendedBooleanChooses querystring when false or qs when true; true is the documented Express 4.x default.
options.inflateBooleanControls whether compressed request bodies are inflated; documented default is true.
options.limitNumber | StringMaximum request-body size; a number represents bytes, while a string is parsed as a size.
options.typeString | FunctionControls which Content-Type is parsed.

Returns

Middleware that parses matching URL-encoded request bodies and populates req.body.

Key points

  • The function is provided directly by Express, so no separate body-parser installation is needed for this middleware.
  • Its role is to decode URL-encoded request bodies before route handlers run.
  • Set extended to true when submitted forms need nested objects or arrays.
  • Compressed request bodies using gzip or deflate are transparently decompressed.

Common mistakes

  • Requests using another character encoding are not supported by this parser.
  • A request with a nonmatching Content-Type is skipped rather than parsed.

Example: Parse a URL-encoded form

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.

When to use it

Parse application/x-www-form-urlencoded forms

HTML form submissions

Decode rich objects and arrays with extended parsing

Nested form data

Accept gzip- or deflate-encoded form bodies

Compressed requests

Interview questions

QWhat does express.urlencoded() do?

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.

QWhat is the purpose of the extended option?

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.

QWhich requests are parsed and what encoding behavior is supported?

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.body
  • body-parser

Source: Express Object · Express.js 4.x. Checked 2026-10-15.