These were a few of the major advantages of using Express.js in web application development.
Processes incoming request bodies, making it easier to handle POST and PUT requests. By parsing the body of an HTTP request and attaching it to the req.body property, it simplifies data extraction and manipulation in server-side logic.
When a client sends a request to the server, the body parser middleware intercepts this request. It parses different types of payloads, such as URL-encoded data or JSON, and then populates the req.body object with parsed data. This process turns the raw HTTP request body into a format that's more convenient to work with in JavaScript.
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
// parse application/json
app.use(bodyParser.json());
app.post('/submit-data', (req, res) => {
console.log(req.body); // Access the parsed body here
res.send('Data Received');
});
app.listen(3000, () => {
console.log('Server is running on port 3000');
});Controllers: Where we implement logic and send the response.