Express.js express.urlencoded() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
express()

Definition

In Express.js, express.urlencoded() is built-in middleware that parses application/x-www-form-urlencoded request bodies — the format HTML forms send by default — and stores the fields on req.body. It is based on body-parser.

Mount it with app.use() before routes that read the body. Pair it with express.json() when the same app also accepts JSON. It runs on your Express server — not in the browser.

Syntax

Call express.urlencoded in your Express.js app. Start with this line.

Express
express.urlencoded([options])
CallWhat it does
express.urlencoded([options])Primary signature.

Install with npm install express. Create the app with const app = express() before you use this API in an Express.js tutorial project.

Library declarations
Express
const express = require("express");
const app = express();

express.urlencoded([options])

Parameters

ParameterDescription
optionsOptional. Parsing settings. Omit for Express 5 defaults.
options.extendedOptional. Default false (Express 5): flatter querystring parsing. true uses qs for nested objects/arrays.
options.limitOptional. Max body size. Default '100kb'. Keep this modest in production.
options.parameterLimitOptional. Max number of parameters. Default 1000. Too many fields raises an error.
options.typeOptional. Which Content-Type to parse. Default 'application/x-www-form-urlencoded'.
options.inflateOptional. Default true: inflate gzip/deflate bodies. false rejects compressed bodies.
options.depthOptional. Max nesting depth for qs when extended: true. Default 32; keep it as low as you can.
options.verifyOptional. verify(req, res, buf, encoding) — inspect the raw buffer; throw to abort.

Return Value

express.urlencoded([options]) returns middleware. Mount it before handlers that read form bodies from req.body.

Express
app.use(express.urlencoded({ extended: true }));
// => middleware mounted on app

Express.js Examples

Example 1 — Parse a Simple Form POST

Mount the parser, then read flat fields from req.body.

Express
const express = require('express');
const app = express();

app.use(express.urlencoded());

app.post('/login', (req, res) => {
  res.json({
    user: req.body.username,
    remember: req.body.remember
  });
});

app.listen(3000);

How It Works

  1. Mount early. app.use(express.urlencoded()) runs before the route.
  2. Match the media type. Default HTML form POSTs use application/x-www-form-urlencoded.
  3. Fill req.body. Each field becomes a property (string values with default extended: false).
  4. Respond from the route. The handler reads req.body.username and sends JSON back.

Example 2 — Nested Fields with extended

Compare flat keys (false) with nested objects (true) for user[name]=Tobi.

Express
const express = require('express');
const app = express();

app.post('/simple', express.urlencoded({ extended: false }), (req, res) => {
  res.json(req.body);
  // Body user[name]=Tobi → { 'user[name]': 'Tobi' }
});

app.post('/nested', express.urlencoded({ extended: true }), (req, res) => {
  res.json(req.body);
  // Body user[name]=Tobi → { user: { name: 'Tobi' } }
});

app.listen(3000);

How It Works

  1. Route-level middleware. Each path gets its own parser options.
  2. extended: false. Uses querystring — bracket keys stay literal property names.
  3. extended: true. Uses qs — user[name] becomes { user: { name: 'Tobi' } }.
  4. Express 5 default is false. Opt into nested parsing when your forms need it.

Example 3 — Forms and JSON Together

Mount both body parsers so HTML forms and JSON clients can hit the same app.

Express
const express = require('express');
const app = express();

app.use(express.urlencoded({ extended: true, limit: '50kb' }));
app.use(express.json({ limit: '50kb' }));

app.post('/profile', (req, res) => {
  res.status(201).json({ saved: req.body });
});

app.listen(3000);

How It Works

  1. Two parsers, two media types. Each middleware only parses requests that match its type.
  2. Same route, same req.body. Handlers do not care which parser ran, as long as the body is populated.
  3. Shared limits. limit: '50kb' caps oversized payloads for both.
  4. Not for file uploads. multipart/form-data needs dedicated upload middleware, not urlencoded.

Runtime Support

express.urlencoded() is Express.js built-in middleware. It runs on a Node.js server (Express 5 needs Node.js 18+). Browsers only submit the form body over HTTP.

✓ Server · Express 4.16+ & 5

express.urlencoded()

Works wherever Express runs: Node.js is the primary target. Bun and Deno can run many Express apps with compatibility layers. Not available in the browser.

Server Node.js runtime API
Node.js 18+ for Express 5 · 14+ typical for Express 4
Supported
Bun Express-compatible server apps
Supported
Deno Via npm compatibility / adapters
Supported
express.urlencoded() Express on Node.js

Bottom line: Study and run these examples with Node.js and the express package. Copy a snippet into a local file and start the server with node.

Frequently Asked Questions

It is built-in middleware that parses application/x-www-form-urlencoded bodies (typical HTML form POSTs) and sets req.body to the parsed fields.
extended: false (Express 5 default) uses the querystring library for flatter keys. extended: true uses qs so nested keys like user[name]=Ada become objects.
Yes, when the same app accepts both HTML forms and JSON APIs. Mount both before routes that read req.body.
Usually the middleware is missing, mounted after the route, or the Content-Type is not urlencoded (for example multipart file uploads need different middleware).
No. It runs on your Node.js server. Browsers only submit the form; the server parses the body.

Next: req.body

Understand the parsed body property your form and JSON parsers fill.

req.body tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful