Express app.get() Method

Beginner
⏱️ 9 min read
📚 Updated: May 2026
🎯 4 Code Examples
Express.js

What you’ll learn

  • How to define GET routes using app.get(path, handler).
  • How to work with route params and query params.
  • How to return JSON responses and render views with GET endpoints.
  • How to avoid common GET routing pitfalls in Express apps.

Overview

app.get() handles HTTP GET requests and is the standard choice for read-only resource retrieval and page rendering.

Read operations

Commonly used for fetching records or listing resources.

Flexible responses

Send JSON, HTML, text, or rendered templates from the same method.

Route matching

Supports static paths, route params, and middleware chaining.

Syntax

javascript
app.get(path, callback)
app.get(path, middleware1, middleware2, ..., callback)
  • path: route path pattern to match for GET requests.
  • callback/middleware: request handler chain for matching route.
  • Use req.params and req.query to read request data.
1

Basic GET route

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

app.get('/', function (req, res) {
  res.send('Welcome to CodeToFun');
});
2

Route params and query params

javascript
app.get('/users/:id', function (req, res) {
  var id = req.params.id;
  var view = req.query.view || 'summary';
  res.json({ id: id, view: view });
});

📋 app.get() vs app.all()

MethodMatchesTypical use
app.get()GET requests onlyRead data, render pages
app.all()All HTTP methodsShared route-level middleware

🧪 Testing checklist

  • Verify response for a valid GET request path.
  • Test route params and query params combinations.
  • Ensure unsupported methods (for example POST) are handled as expected.
  • Check status codes and response format consistency.

Pitfalls to avoid

Route order issues

Unexpected matches

Define specific GET routes before broad wildcard routes.

Parameter confusion

Wrong data source

Use req.params for path params and req.query for query string values.

No validation

Unreliable responses

Validate incoming params and return clear error responses.

❓ FAQ

It defines a route handler for HTTP GET requests on the specified path.
Use it to fetch resources, render pages, or return read-only data from APIs.
Use placeholders like /users/:id and access values via req.params.id.
Use req.query, for example req.query.page or req.query.search.
Yes. You can pass multiple middleware functions before the final response handler.

Summary

  • Core use: app.get() handles GET requests for read operations.
  • Inputs: combine path params and query params for flexible endpoints.
  • Practice: keep routes specific, validate inputs, and return consistent responses.
Did you know?

app.get(path, handler) handles HTTP GET requests and is most commonly used for fetching pages or data.

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.

4 people found this page helpful