How do you define a route in Express?
Ask by ICSM Computer
Updated 03 Apr 2025
In Express (a Node.js web framework), you define a route using methods like
app.get(),app.post(),app.put(), etc., depending on the HTTP verb you want to handle.Here’s the basic syntax:
Breakdown:
app.get()defines a GET route.The first argument (
'/example') is the route path.The second argument is a callback function (called a route handler) with
req(request) andres(response) parameters.res.send()sends a response to the client.Other common HTTP methods: