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

Express.js · Module

app.get

Registers callback functions for a route path and HTTP GET requests. The route also handles HEAD requests unless an earlier app.head() route exists for that path.

How it works

app.get() registers callback functions for a route path and the HTTP GET method. When an incoming GET request matches that path, Express runs the callbacks; unless a separate HEAD route was registered first, the same route also handles HEAD requests.

Syntax

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

Parameters

NameTypeDescription
pathString or patternRoute path to match against incoming requests.
callback functionsFunctionOne or more callback functions invoked for matching requests.

Returns

The documentation describes route registration and does not specify a return value for this use.

Key points

  • It maps a URL path to callback functions for incoming GET requests.
  • The method belongs to Express's family of application routing methods derived from HTTP methods.
  • The corresponding application method uses the HTTP method name in lowercase, such as get, post, or put.
  • Other HTTP verbs have parallel app methods, including app.post() and app.put().

Common mistakes

  • A GET route also handles HEAD requests automatically when no earlier app.head() route exists for that path.
  • Register app.head() before app.get() when HEAD needs behavior different from the GET route.

Example: Basic GET route

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

app.get('/hello', (req, res) => {
  res.send('Hello, world!');
});

app.listen(3000);

Creates a GET route at /hello and sends a plain-text response.

When to use it

Serve GET resources

Expose a read-only endpoint such as /users or /health.

Generate responses

Return HTML, JSON, or text for a browser or API client.

Compose route middleware

Attach multiple handlers for validation, authentication, and response handling.

Interview questions

QWhat does app.get() do?

app.get() defines a route for HTTP GET requests. Its arguments are a path and one or more callback functions that Express invokes when the request matches.

Follow-up: How does it differ from app.use()? app.get() is method-specific, while app.use() mounts middleware without restricting it to GET.

QWhat arguments does app.get() accept?

The first argument is the route path, and the remaining arguments are callback functions. The callbacks handle the matching request and typically send a response or pass control onward.

Follow-up: What happens if no callback ends the request or calls next()? The request can remain unresolved until the client times out.

QDoes app.get() handle HEAD requests?

A registered app.get() route is also used for HEAD requests when app.head() was not registered for that path beforehand. This lets Express provide HEAD handling without duplicating the route.

Follow-up: How can HEAD behavior be customized? Register app.head() for the path before registering app.get().

  • app.head()
  • app.post()
  • app.put()
  • app.delete()
  • app.all()
  • app.route()

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