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

Express.js · Function

post

app.post() routes HTTP POST requests matching a specified path to one or more callback functions. The callbacks can act as middleware and may pass control to later handlers or skip the remaining callbacks for the current route.

How it works

app.post() registers one or more callbacks for HTTP POST requests whose URL matches the supplied path. Express invokes the callbacks in order, allowing middleware to process the request before a handler sends the response or passes control onward.

Syntax

app.post(path, [callback ...], callback)

Parameters

NameTypeDescription
pathString | RegExp | ArrayA string, path pattern, regular expression, or array of supported path specifications to match.
callback…FunctionOne middleware function, multiple callbacks, an array of callbacks, or a combination of these.

Key points

  • Use app.post() to associate a path and callback chain with incoming HTTP POST requests.
  • The path can be a literal string, a path pattern, a regular expression, or an array of supported path forms.
  • Callbacks may be supplied individually, as a comma-separated sequence, in an array, or through a combination of these forms.
  • A callback can use next('route') to skip the rest of the callbacks belonging to the current route.
  • Path matching supports the same path examples documented for Express route paths.

Common mistakes

  • When using several callbacks, treat them as middleware and ensure control is passed onward when a callback does not finish the response.
  • A callback can skip the remaining callbacks for the current route with next('route').

Example: Handle a JSON POST request

import express from 'express';

const app = express();

app.use(express.json());
app.post('/users', (req, res) => {
  res.status(201).json({ user: req.body });
});

app.listen(3000);

Parses JSON request bodies, then handles POST requests to /users and returns the submitted data.

When to use it

Build a POST API endpoint

Create an endpoint that accepts submitted form or JSON data and returns a response.

Compose request middleware

Run authentication, validation, or request preprocessing before the final handler.

Reuse handlers across path patterns

Match several URL forms with one callback chain using supported path specifications.

Interview questions

QWhat does app.post() do?

app.post() defines a route for HTTP POST requests at a specified path. Its callbacks receive the request and response objects and can process input or send a response.

Follow-up: How can a POST route use multiple handlers? Pass multiple callbacks; they run as middleware in order, and a handler can pass control onward with next().

QWhat forms can the path argument take?

The path may be a string, path pattern, regular expression, or an array combining those forms. Express matches the incoming request URL against that path before invoking the callbacks.

Follow-up: Why might an array be useful? It lets one route declaration match multiple path specifications without duplicating the callback list.

QHow does app.post() support middleware chains?

The callback argument may be one middleware function, several comma-separated functions, an array of functions, or a combination. These callbacks can invoke next('route') to skip the remaining callbacks for the current route.

Follow-up: What happens after next('route')? Express bypasses the rest of that route's callbacks and proceeds to a subsequent matching route, if one exists.

  • app.get()
  • app.put()
  • app.delete()
  • app.query()
  • router.post()
  • express.Router()

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