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

Express.js · Module

app.post

app.post() registers one or more handlers for HTTP POST requests matching a specified path. The path supports strings, patterns, regular expressions, or arrays of these forms.

How it works

app.post() registers callback functions for HTTP POST requests that match a specified path. The path can be a string, path pattern, regular expression, or array, and the callbacks run as route middleware for matching requests.

Syntax

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

Parameters

NameTypeDescription
pathString | RegExp | ArrayPath or path pattern matched by the route; accepts a string, regular expression, or array of combinations.
callback functionsFunction | Function[]One or more callback functions used as route middleware and the final request handler.

Returns

Routes HTTP POST requests to the specified path with the specified callback functions.

Key points

  • Use app.post() to register handlers specifically for POST requests at a chosen route.
  • The route path may be a literal path or a pattern interpreted by Express.
  • Regular expressions and arrays let one registration cover more advanced matching requirements.
  • Handlers may be supplied individually or as a sequence of middleware functions.
  • The method name follows the HTTP verb, making app.post() the application-level POST routing method.

Common mistakes

  • A missing path matches every request, so specify the route path when broad matching is not intended.
  • Multiple callbacks can form a processing chain; use next('route') when a route-level condition should skip the remaining callbacks.

Example: Handle a POST request

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

app.post('/users', (req, res) => {
  res.send('User created');
});

app.listen(3000);

Creates a POST route at /users and sends a response when that route receives a matching request.

When to use it

Resource creation

Create resources such as users, orders, or comments from submitted request data.

Middleware pipelines

Run validation, authorization, and business logic in an ordered handler chain.

Command and form endpoints

Handle form submissions or API commands addressed to a specific endpoint.

Interview questions

QWhat does app.post() do?

app.post() routes HTTP POST requests to a selected path and runs the supplied callback functions for matching requests. The path may be a string, pattern, regular expression, or array.

Follow-up: How can several handlers be composed? Pass multiple callback functions, which behave like middleware, and call next('route') to bypass the remaining callbacks for that route.

QWhat types of paths can app.post() accept?

The first argument is the route path. It accepts a String, RegExp, or Array containing combinations of supported path forms.

Follow-up: What does an array provide? It lets one route definition match multiple path representations through a single registration.

QWhen is the app.post() handler executed?

The callback receives the request and response objects, and can send the response for the POST request. Express invokes it when both the path and HTTP method match.

Follow-up: How would you add preprocessing? Supply additional callback functions before the final handler and pass control between them with next().

  • app.get()
  • app.put()
  • app.delete()
  • app.route()
  • router.post()

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