LOGBOOK

HELP

Quiz Entry - updated: 2026.07.05

How do you create a basic Express route handler?

Call a method like router.get() with a URL path and a callback that receives (req, res) and sends the response.

import express from 'express';
const router = express.Router();

// Handle GET requests to '/'
router.get('/', function(req, res) {
    res.send('Hello World!');
});

export default router;

Components:

  1. Import Express and create a router
  2. Define routes with HTTP method + path + handler
  3. Export the router for use in main app

Request: GET http://localhost/hello Response: Hello World!

Multiple routes in one file:

router.get('/users', handleGetUsers);
router.post('/users', handleCreateUser);
router.get('/users/:id', handleGetUser);

Go deeper:

From Quiz: WEBT / Backend Development | Updated: Jul 05, 2026