Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
8 views1 page

Routing

Routing in an application defines how endpoints respond to client requests using methods of the Express app object, such as app.get() for GET requests and app.post() for POST requests. Callback functions are specified to handle requests for particular routes and methods, and multiple callbacks can be used with the next function to control the flow. An example provided demonstrates a basic route that responds with 'hello world' to a GET request at the homepage.

Uploaded by

Sandhya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views1 page

Routing

Routing in an application defines how endpoints respond to client requests using methods of the Express app object, such as app.get() for GET requests and app.post() for POST requests. Callback functions are specified to handle requests for particular routes and methods, and multiple callbacks can be used with the next function to control the flow. An example provided demonstrates a basic route that responds with 'hello world' to a GET request at the homepage.

Uploaded by

Sandhya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Routing refers to how an application’s endpoints (URIs) respond to client requests.

For an
introduction to routing, see Basic routing.

You define routing using methods of the Express app object that correspond to HTTP methods;
for example, app.get() to handle GET requests and app.post to handle POST requests. For a
full list, see app.METHOD. You can also use app.all() to handle all HTTP methods
and app.use() to specify middleware as the callback function (See Using middleware for details).

These routing methods specify a callback function (sometimes called “handler functions”) called
when the application receives a request to the specified route (endpoint) and HTTP method. In
other words, the application “listens” for requests that match the specified route(s) and
method(s), and when it detects a match, it calls the specified callback function.

In fact, the routing methods can have more than one callback function as arguments. With
multiple callback functions, it is important to provide next as an argument to the callback
function and then call next() within the body of the function to hand off control to the next
callback.

The following code is an example of a very basic route.

const express = require('express')


const app = express()

// respond with "hello world" when a GET request is made to the homepage
app.get('/', (req, res) => {
res.send('hello world')
})

You might also like