Express.js is a web application framework for Node.js. It provides a robust set of features for web and mobile applications, including a routing system.
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).
Example:
const express = require(‘express’);
const app = express();
// Create a route for the path “/” with a GET request
app.get(‘/’, (req, res) => {
res.send(‘Hello World!’);
});
// Create a route for the path “/about” with a GET request
app.get(‘/about’, (req, res) => {
res.send(‘This is an example of the Express.js routing system.’);
});
// Start the server on port 3000
app.listen(3000, () => {
console.log(‘Server is listening on port 3000…’);
});