Home Express.js Application app.get() Express.js app.get() Method 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.
app.get(path, callback)
app.get(path, ...callbacks)
app.get(name) Call What 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 const express = require("express");
const app = express();
app.get(path, callback)
app.get(path, ...callbacks)
app.get(name) Parameters Parameter Description path Required. Path to match for GET. Strings match the whole path. Arrays match any listed path. callback Required. One or more handlers: (req, res, next) => { … }. Can call next('route') to skip remaining callbacks on this route. name Required. 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).
// 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 1. Homepage GET 2. Params and query 3. Read a setting Example 1 — Homepage GET Classic hello-world route from the Express docs style.
const express = require('express');
const app = express();
app.get('/', (req, res) => {
res.send('GET request to homepage');
});
app.listen(3000); GET /
→ GET request to homepage
POST / → no match on this route (use app.post for POST) How It Works Create the app. express() returns the application object.Register GET /. Only HTTP GET to the homepage runs this handler.Send a body. res.send finishes the response with plain text.Listen. app.listen(3000) accepts connections on port 3000.Example 2 — Params and Query Combine a path parameter with a query string.
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); GET /users/42?fields=name,email
→ { "id": "42", "fields": "name,email" }
GET /users/7
→ { "id": "7", "fields": "all" } How It Works Path param. :id captures a segment into req.params.id.Query string. ?fields=... lands in req.query.fields.Default. If fields is missing, the handler uses 'all'.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.
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); My Site
…/views (project views directory)
GET /meta
→ { "title": "My Site" } How It Works Store a value. app.set('title', 'My Site') saves a custom setting.Read it back. app.get('title') (one argument, no handler) returns that value.Built-ins too. Names like 'views' come from Express’s settings table.Still route with GET. app.get('/meta', …) is the routing form — path starts with /.Compatibility
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 What does Express.js app.get() do? 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.
How do I tell routing get from settings get? 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).
How do route parameters work? Use a placeholder like /users/:id and read the value from req.params.id inside the handler.
How do I read query strings? Use req.query. For example, /search?q=express gives req.query.q === 'express'.
Can browsers run app.get()? No. Express runs on Node.js. Browsers only send HTTP GET requests to your server.
CODETOFUN NEWS
Stay Ahead in Tech Get the latest IT news, programming updates, and technology trends directly on your phone.
About the author Developer, cloud engineer, and technical writer
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
Helpful Share Copy link Suggestion