Express.js is a web application framework for Node.js that enables you to handle requests and responses. It provides a layer of abstraction over the Node.js HTTP module, allowing you to more easily create web applications and APIs.
To handle requests in Express.js, you can use the app.METHOD() methods, where METHOD is the HTTP method of the request (e.g. GET, POST, PUT, DELETE).
For example, to handle a GET request, you can use the app.get() method:
app.get(‘/’, (req, res) => {
// Handle the request
res.send(‘Hello World!’);
});
You can also use the app.all() method to handle all HTTP methods for a given route:
app.all(‘/’, (req, res) => {
// Handle the request
res.send(‘Hello World!’);
});