Express.js app.METHOD() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Application

Definition

app.METHOD() is the Express pattern for HTTP verb routes. Replace METHOD with a lowercase verb: app.get(), app.post(), app.put(), app.delete(), and many others.

Each call matches one verb on a path. Shared logic for every verb belongs on app.all(). Chain several verbs on one path with app.route().

Syntax

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

Express
app.METHOD(path, callback)
app.METHOD(path, ...callbacks)
app['m-search'](path, callback)
CallWhat it does
app.METHOD(path, callback)Primary signature.
app.METHOD(path, ...callbacks)Related call form.
app['m-search'](path, callback)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.METHOD(path, callback)
app.METHOD(path, ...callbacks)
app['m-search'](path, callback)

Parameters

ParameterDescription
pathRequired. Route to match. Strings match the whole path. Arrays match any listed path.
callbackRequired. One or more handlers: (req, res, next) => { … }. Can call next('route') to skip remaining callbacks on this route.
app.getRequired. Read a resource / page
app.postRequired. Create a resource
app.putRequired. Replace / update
app.deleteRequired. Remove a resource
app.patchRequired. Partial update

Return Value

app.METHOD() (lowercase method names such as get, post, …) returns the same application object (app), which is usually ignored.

Express
app.post('/login', login);
// => app

app.put('/items/:id', replace).delete('/items/:id', remove);

Express.js Examples

Example 1 — Same Path, Two Verbs

Official-style: get and post on / are separate METHOD routes.

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

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

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

app.listen(3000);

How It Works

  1. Same URL, different verbs. Path is / for both routes.
  2. GET handler. Only HTTP GET runs the first callback.
  3. POST handler. Only HTTP POST runs the second.
  4. Other verbs miss. PUT/DELETE need their own app.METHOD (or app.all).

Example 2 — Bracket Notation

Methods that are invalid JavaScript property names use brackets (from the Express docs).

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

app['m-search']('/', (req, res) => {
  res.send('M-SEARCH request to homepage');
});

app.listen(3000);

How It Works

  1. Odd method name. m-search contains a hyphen.
  2. Bracket access. app['m-search'] is the valid way to call that router.
  3. Same signature. Path + callback work like any other METHOD.
  4. Rare in apps. Day-to-day APIs stick to get/post/put/delete/patch.

Example 3 — Chain with app.route()

One path, several METHOD handlers without repeating the path string.

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

app.route('/book')
  .get((req, res) => {
    res.send('Get a book');
  })
  .post((req, res) => {
    res.send('Add a book');
  })
  .put((req, res) => {
    res.send('Update the book');
  });

app.listen(3000);

How It Works

  1. One path. app.route('/book') names the resource once.
  2. Chain verbs. .get, .post, and .put are METHOD helpers on that route.
  3. Same matching rules. Each link still matches only its HTTP verb.
  4. Fewer typos. You do not repeat '/book' on every line.

Runtime Support

app.METHOD() helpers are Express.js application methods. They run on a Node.js server (Express 5 needs Node.js 18+). Browsers only send HTTP requests.

✓ Server · Express 4 & 5

app.METHOD()

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.METHOD() 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 the family of routing methods where METHOD is an HTTP verb in lowercase — for example app.get(), app.post(), and app.delete(). Each one matches only that verb.
app.METHOD() matches one HTTP verb. app.all() runs for every verb on the path.
No. String patterns match the whole request path. app.get('/apple') matches /apple, not /apple/images. app.use() behaves differently.
Use bracket notation: app['m-search'](path, handler), because m-search is not a valid JavaScript property name with dot syntax.
No. These methods register routes on your Node.js server. Browsers only send HTTP requests with a method and path.

Next: app.mountpath

See the path patterns where a sub-app is mounted.

app.mountpath 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