Express.js app.get() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Application

Definition

In Express.js, app.get() is overloaded. Most often it registers handlers for HTTP GET on a path (pages and read APIs). With a single setting name and no handler, it reads an application setting set by app.set().

As a route method it is one of Express’s app.METHOD() helpers: only GET matches. POST or DELETE to the same URL need their own routes. Express runs on Node.js — browsers only send the GET request.

Syntax

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

Express
app.get(path, callback)
app.get(path, ...callbacks)
app.get(name)
CallWhat it does
app.get(path, callback)Primary signature.
app.get(path, ...callbacks)Related call form.
app.get(name)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.get(path, callback)
app.get(path, ...callbacks)
app.get(name)

Parameters

ParameterDescription
pathRequired. Path to match for GET. 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.
nameRequired. Setting to read — for example 'views', 'view engine', or a custom key you stored with app.set.

Return Value

app.get() has two jobs. With a path and handler(s), it registers a GET route and returns app (usually ignored). With only a setting name, it returns that setting’s stored value (any type).

Express
// Route form → returns app
app.get('/users', listUsers);

// Setting form → returns the stored value
app.set('title', 'Docs');
app.get('title'); // 'Docs'

Express.js Examples

Example 1 — Homepage GET

Classic hello-world route from the Express docs style.

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

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

app.listen(3000);

How It Works

  1. Create the app. express() returns the application object.
  2. Register GET /. Only HTTP GET to the homepage runs this handler.
  3. Send a body. res.send finishes the response with plain text.
  4. Listen. app.listen(3000) accepts connections on port 3000.

Example 2 — Params and Query

Combine a path parameter with a query string.

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

app.get('/users/:id', (req, res) => {
  res.json({
    id: req.params.id,
    fields: req.query.fields || 'all'
  });
});

app.listen(3000);

How It Works

  1. Path param. :id captures a segment into req.params.id.
  2. Query string. ?fields=... lands in req.query.fields.
  3. Default. If fields is missing, the handler uses 'all'.
  4. JSON out. res.json sends a structured response for APIs.

Example 3 — Read a Setting

The other overload: app.get(name) returns a value stored with app.set.

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

app.set('title', 'My Site');

console.log(app.get('title')); // 'My Site'
console.log(app.get('views')); // default views path

app.get('/meta', (req, res) => {
  res.json({ title: app.get('title') });
});

app.listen(3000);

How It Works

  1. Store a value. app.set('title', 'My Site') saves a custom setting.
  2. Read it back. app.get('title') (one argument, no handler) returns that value.
  3. Built-ins too. Names like 'views' come from Express’s settings table.
  4. Still route with GET. app.get('/meta', …) is the routing form — path starts with /.

Runtime Support

app.get() is an Express.js application method. It runs on a Node.js server (Express 5 needs Node.js 18+). Browsers only send GET requests.

✓ Server · Express 4 & 5

app.get()

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.get() 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 has two jobs: register handlers for HTTP GET on a path, or read a named application setting when you pass only a setting name.
app.get('/path', handler) is a route. app.get('settingName') with one string and no handler reads a setting (same names you use with app.set).
Use a placeholder like /users/:id and read the value from req.params.id inside the handler.
Use req.query. For example, /search?q=express gives req.query.q === 'express'.
No. Express runs on Node.js. Browsers only send HTTP GET requests to your server.

Next: app.listen()

Bind your Express app to a port and start accepting requests.

app.listen() 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