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

Express.js · Function

get

Registers callback functions for HTTP GET requests matching a specified route path. It also handles HEAD requests for that path unless app.head() was registered there first.

How it works

Call app.get() with a path and one or more callback functions to register handling for matching HTTP GET requests. Express invokes the callbacks when a request matches both the route path and method; unless a separate HEAD handler was registered first for that path, this route also handles HEAD requests.

Syntax

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

Parameters

NameTypeDescription
pathstring or pattern accepted by Express routingRoute path to match, such as /health.
callbackfunctionOne or more callback functions invoked for a matching request.

Key points

  • Use app.get(path, callbacks) to associate a path with handlers for incoming GET requests.
  • The callback is the route handler that Express invokes after the request matches the route.
  • A handler runs only when both the endpoint and HTTP method match the incoming request.
  • app.get() is one of the application methods documented explicitly for a commonly used HTTP method.
  • The application API provides method-based routing for HTTP methods beyond GET, including POST and PUT.

Common mistakes

  • A GET route also handles HEAD requests by default for the same path; define app.head() first when separate HEAD behavior is required.

Example: Register a GET route

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

app.get('/health', (req, res) => {
  res.json({ ok: true });
});

app.listen(3000);

Creates a GET route that returns JSON at /health, then starts the server on port 3000.

When to use it

Serve JSON data

Expose a read-only resource endpoint.

Render a page

Return an HTML page for a browser route.

Implement health checks

Provide a liveness or readiness endpoint.

Interview questions

QWhat does app.get() do?

app.get() registers a route for HTTP GET requests. Its first argument is the route path, followed by callback functions that Express runs when the path and method match.

Follow-up: How can several handlers participate in one route? Pass multiple callback functions; each handler must complete the response or delegate so processing can continue.

QHow does Express select an app.get() route?

The method is attached to an Express application instance and uses a path plus callback functions. Express selects the route when an incoming request matches both the path and GET method.

Follow-up: How would you support another HTTP method? Use the corresponding application method, such as app.post(), app.put(), or app.delete().

QDoes app.get() handle HEAD requests?

app.get() also covers HTTP HEAD for its path when app.head() was not previously called for that path. This provides default HEAD handling without registering a separate handler.

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

  • app.post()
  • app.put()
  • app.delete()
  • app.head()
  • app.route()
  • express.Router

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