Routing refers to determining how an application responds to a client request to a particular endpoint, which is a URI (or path) and a specific HTTP request method (GET, POST, and so on).
Below is an example of a simple “Hello World” route in ExpressJS:
1 2 3 4 5 6 7 8 9 10 11 |
const express = require('express') const app = express() app.get('/', (req, res) => { res.send('Hello World!') }) app.listen(3000, () => { console.log('Demo app listening on port 3000!') }) |
In this example, the app.get()
method is used to define a GET request route that matches the root URL path (/
). When a GET request is received at this URL, the callback function passed to app.get()
is executed, which sends a response to the client with the message "Hello World!"
. The app.listen()
method is used to start the ExpressJS application and listen on port 3000.
You can test this route by running the above code and navigating to http://localhost:3000
in your web browser. You should see the message "Hello World!"
displayed in the browser.