Express.js app.post() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Application

Definition

In Express.js, app.post() registers handlers for HTTP POST requests on a path. APIs often use it to create a resource, for example POST /users with a JSON body.

It is one of Express’s app.METHOD() routing methods: only POST matches. Pair it with express.json() (or express.urlencoded()) so req.body is populated.

Syntax

Call app.post in your Express.js app. Start with this line.

Express
app.post(path, callback)
app.post(path, ...callbacks)
CallWhat it does
app.post(path, callback)Primary signature.
app.post(path, ...callbacks)Related call form.

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();

app.post(path, callback)
app.post(path, ...callbacks)

Parameters

ParameterDescription
pathRequired. Route path to match. Strings match the whole path. Arrays register the same handlers for each path.
callbackRequired. Middleware-style handlers (req, res, next). You may pass several, or an array of them.

Return Value

app.post() returns the same application object (app), so chaining is possible. In real apps you almost always ignore the return value and register each route on its own line.

Express
// Chaining works, but is uncommon:
app.post('/login', login).get('/login', form);

// Typical style — ignore the return value:
app.post('/login', login);
app.get('/login', form);

Express.js Examples

Example 1 — Basic POST Route

Official-style homepage POST — no body parsing needed.

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

app.post('/', (req, res) => {
  res.send('POST request to homepage');
});

app.listen(3000);

How It Works

  1. Register POST only. app.post('/', …) ignores GET and PUT.
  2. Match the path. A POST to / enters the handler.
  3. Send a body. res.send(…) finishes with status 200 by default.
  4. Other verbs need other routes. Add app.get('/') if you also want to serve the page.

Example 2 — JSON Create (201)

Parse JSON, create a user, return the new resource.

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

app.use(express.json());

const users = [];
let nextId = 1;

app.post('/users', (req, res) => {
  const name = req.body && req.body.name;
  if (!name) {
    return res.status(400).json({ error: 'name is required' });
  }
  const user = { id: nextId++, name: String(name) };
  users.push(user);
  res.status(201).json(user);
});

app.listen(3000);

How It Works

  1. Parse JSON. express.json() fills req.body for Content-Type: application/json.
  2. Validate. Missing name returns 400 and stops.
  3. Create. Push a new object with an id into the in-memory list.
  4. Respond 201. res.status(201).json(user) signals a successful create.

Example 3 — Validate Then Create

Multiple callbacks: a check runs before the create handler.

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

app.use(express.json());

function requireEmail(req, res, next) {
  if (!req.body || !req.body.email) {
    return res.status(400).json({ error: 'email is required' });
  }
  next();
}

app.post('/signup', requireEmail, (req, res) => {
  res.status(201).json({
    ok: true,
    email: req.body.email
  });
});

app.listen(3000);

How It Works

  1. Shared check. requireEmail runs first like middleware.
  2. Fail early. Bad input sends 400 and never calls the next function.
  3. Continue. next() moves to the create handler.
  4. Respond. The final callback returns 201 with a small JSON body.

Runtime Support

app.post() is an Express.js application method. It runs on a Node.js server (Express 5 needs Node.js 18+). Browsers only send the POST request.

✓ Server · Express 4 & 5

app.post()

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

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
app.post() Express on Node.js

Bottom line: Run examples with Node.js and the express package, then POST with curl, Postman, or fetch.

Frequently Asked Questions

It registers one or more handlers for HTTP POST requests on a path. Only POST matches — GET or PUT to the same path need their own routes.
Express does not parse JSON or form bodies by default. Add express.json() or express.urlencoded() before your routes so req.body is filled.
Often 201 Created with the new resource (or its id) in the body. 200 is fine for simple acknowledgements; 204 if there is no body to return.
No. Like other app.METHOD routes, a string path matches the whole request path. app.post('/apple') matches /apple, not /apple/images — unlike app.use('/apple').
No. Express runs on a Node.js server. Browsers only send HTTP POST requests (forms, fetch, XHR) to your API.

Next: app.put()

Handle HTTP PUT requests to replace or update resources.

app.put() tutorial →

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